Browse Source

Initial commit

logicp 7 years ago
commit
9e551f5d8b

+ 26 - 0
heartbeat_comment_like/config/install/flag.flag.heartbeat_like.yml

@@ -0,0 +1,26 @@
+langcode: en
+status: true
+dependencies:
+  module:
+    - heartbeat
+id: heartbeat_like
+label: Heartbeat Like
+entity_type: heartbeat
+global: false
+weight: 0
+flag_short: 'Praise ([flagcount:count])'
+flag_long: ''
+flag_message: ''
+unflag_short: 'Reee ([flagcount:count])'
+unflag_long: ''
+unflag_message: ''
+unflag_denied_text: ''
+flag_type: 'entity:heartbeat'
+link_type: ajax_link
+flagTypeConfig:
+  show_in_links: {  }
+  show_as_field: true
+  show_on_form: false
+  show_contextual_link: false
+  access_author: ''
+linkTypeConfig: {  }

+ 11 - 0
heartbeat_comment_like/heartbeat_like.info.yml

@@ -0,0 +1,11 @@
+name : Heartbeat Like
+type: module
+description : "Allows you to like Heartbeats"
+dependencies:
+  - flag
+  - token
+  - heartbeat
+  - statusmessage
+
+core: '8.x'
+project: 'heartbeat'

+ 48 - 0
heartbeat_comment_like/heartbeat_like.module

@@ -0,0 +1,48 @@
+<?php
+
+/**
+ * Implements hook_form_FORM_ID_alter().
+ * Tokenize the flag link strings.
+ */
+function heartbeat_like_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
+
+  if ($form_id == 'flag_add_form' || $form_id == 'flag_edit_form')  {
+
+    // Setup for the "Browse available tokens" link.
+    $browse_array = array(
+      '#theme' => 'token_tree_link',
+      '#token_types' => array('heartbeat_like'),
+    );
+
+    // Validation options to add to form elements.
+    $token_options = array(
+      '#element_validate' => array('token_element_validate'),
+      '#token_types' => array(),
+      '#min_tokens' => 1,
+      '#max_tokens' => 10,
+    );
+
+    // Let admin know that this field is now tokenized.
+    $form['messages']['flag_short']['#description'] .= '<br />' . t('This field supports tokens (try: "Like [flagcount:count]")');
+    $form['messages']['flag_short']['#suffix'] = render($browse_array);
+    $form['messages']['flag_short'] += $token_options;
+
+    $form['messages']['unflag_short']['#description'] .= '<br />' . t('This field supports tokens (try: "Unlike [flagcount:count]")');
+    $form['messages']['unflag_short']['#suffix'] = render($browse_array);
+    $form['messages']['unflag_short'] += $token_options;
+  }
+
+}
+
+/**
+ * Implements hook_preprocess_HOOK().
+ */
+function heartbeat_like_preprocess_flag(&$variables) {
+
+  // Replace the link title with any tokens.
+  $token = Drupal::token();
+  $variables['title'] = $token->replace($variables['title'], array(
+    'flag_id' => $variables['flag']->id(),
+    'entity_id' => $variables['flaggable']->id(),
+  ));
+}

+ 70 - 0
heartbeat_comment_like/heartbeat_like.tokens.inc

@@ -0,0 +1,70 @@
+<?php
+
+/**
+ * @file
+ * Token for heartbeat_like.
+ */
+
+use Drupal\Core\Render\BubbleableMetadata;
+
+/**
+ * Implements hook_token_info().
+ */
+function heartbeat_like_token_info() {
+
+  $types = array();
+  $tokens = array();
+
+  // Flag tokens.
+  $types['flagcount'] = array(
+    'name' => t('Flags count'),
+    'description' => t('Tokens related to flag count (heartbeat_like) module.'),
+  );
+  $tokens['flagcount']['count'] = array(
+    'name' => t('Count'),
+    'description' => t('Number of times the flag has been flagged.'),
+    'needs-data' => 'flag',
+  );
+
+  return array(
+    'types' => $types,
+    'tokens' => $tokens,
+  );
+}
+
+ /**
+  * Implements hook_tokens().
+  */
+function heartbeat_like_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
+  $replacements = array();
+
+  if ($type == 'flagcount') {
+    foreach ($tokens as $name => $original) {
+      // Find the desired token by name
+      switch ($name) {
+        case 'count':
+
+          if (isset($data['flag_id']) && isset($data['entity_id'])) {
+
+            // Query the db for the count associated with this entity.
+            $query = \Drupal::database()->select('flag_counts', 'fc');
+            $query->fields('fc', ['count']);
+            $query->condition('fc.flag_id', $data['flag_id']);
+            $query->condition('fc.entity_id', $data['entity_id']);
+            $count_db = $query->execute()->fetchAssoc();
+
+            if (!isset($count_db['count'])) {
+              $count_db['count'] = 0;
+            }
+
+            $replacements[$original] = $count_db['count'];
+          }
+
+          break;
+      }
+    }
+  }
+
+  // Return the replacements.
+  return $replacements;
+}

+ 26 - 0
heartbeat_like/config/install/flag.flag.heartbeat_like.yml

@@ -0,0 +1,26 @@
+langcode: en
+status: true
+dependencies:
+  module:
+    - heartbeat
+id: heartbeat_like
+label: Heartbeat Like
+entity_type: heartbeat
+global: false
+weight: 0
+flag_short: 'Praise ([flagcount:count])'
+flag_long: ''
+flag_message: ''
+unflag_short: 'Reee ([flagcount:count])'
+unflag_long: ''
+unflag_message: ''
+unflag_denied_text: ''
+flag_type: 'entity:heartbeat'
+link_type: ajax_link
+flagTypeConfig:
+  show_in_links: {  }
+  show_as_field: true
+  show_on_form: false
+  show_contextual_link: false
+  access_author: ''
+linkTypeConfig: {  }

+ 11 - 0
heartbeat_like/heartbeat_like.info.yml

@@ -0,0 +1,11 @@
+name : Heartbeat Like
+type: module
+description : "Allows you to like Heartbeats"
+dependencies:
+  - flag
+  - token
+  - heartbeat
+  - statusmessage
+
+core: '8.x'
+project: 'heartbeat'

+ 48 - 0
heartbeat_like/heartbeat_like.module

@@ -0,0 +1,48 @@
+<?php
+
+/**
+ * Implements hook_form_FORM_ID_alter().
+ * Tokenize the flag link strings.
+ */
+function heartbeat_like_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
+
+  if ($form_id == 'flag_add_form' || $form_id == 'flag_edit_form')  {
+
+    // Setup for the "Browse available tokens" link.
+    $browse_array = array(
+      '#theme' => 'token_tree_link',
+      '#token_types' => array('heartbeat_like'),
+    );
+
+    // Validation options to add to form elements.
+    $token_options = array(
+      '#element_validate' => array('token_element_validate'),
+      '#token_types' => array(),
+      '#min_tokens' => 1,
+      '#max_tokens' => 10,
+    );
+
+    // Let admin know that this field is now tokenized.
+    $form['messages']['flag_short']['#description'] .= '<br />' . t('This field supports tokens (try: "Like [flagcount:count]")');
+    $form['messages']['flag_short']['#suffix'] = render($browse_array);
+    $form['messages']['flag_short'] += $token_options;
+
+    $form['messages']['unflag_short']['#description'] .= '<br />' . t('This field supports tokens (try: "Unlike [flagcount:count]")');
+    $form['messages']['unflag_short']['#suffix'] = render($browse_array);
+    $form['messages']['unflag_short'] += $token_options;
+  }
+
+}
+
+/**
+ * Implements hook_preprocess_HOOK().
+ */
+function heartbeat_like_preprocess_flag(&$variables) {
+
+  // Replace the link title with any tokens.
+  $token = Drupal::token();
+  $variables['title'] = $token->replace($variables['title'], array(
+    'flag_id' => $variables['flag']->id(),
+    'entity_id' => $variables['flaggable']->id(),
+  ));
+}

+ 88 - 0
heartbeat_like/heartbeat_like.tokens.inc

@@ -0,0 +1,88 @@
+<?php
+
+/**
+ * @file
+ * Token for heartbeat_like.
+ */
+
+use Drupal\Core\Render\BubbleableMetadata;
+
+/**
+ * Implements hook_token_info().
+ */
+function heartbeat_like_token_info() {
+
+  $types = array();
+  $tokens = array();
+
+  // Flag tokens.
+  $types['flagcount'] = array(
+    'name' => t('Flags count'),
+    'description' => t('Tokens related to flag count (heartbeat_like) module.'),
+  );
+  $tokens['flagcount']['count'] = array(
+    'name' => t('Count'),
+    'description' => t('Number of times the flag has been flagged.'),
+    'needs-data' => 'flag',
+  );
+
+  return array(
+    'types' => $types,
+    'tokens' => $tokens,
+  );
+}
+
+ /**
+  * Implements hook_tokens().
+  */
+function heartbeat_like_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
+  $replacements = array();
+
+  if ($type == 'flagcount') {
+    foreach ($tokens as $name => $original) {
+      // Find the desired token by name
+      switch ($name) {
+        case 'count':
+
+          if (isset($data['flag_id']) && isset($data['entity_id'])) {
+
+            // Query the db for the count associated with this entity.
+            $query = \Drupal::database()->select('flag_counts', 'fc');
+            $query->fields('fc', ['count']);
+            $query->condition('fc.flag_id', $data['flag_id']);
+            $query->condition('fc.entity_id', $data['entity_id']);
+            $count_db = $query->execute()->fetchAssoc();
+
+            if (!isset($count_db['count'])) {
+//              unset ($replacements[$original]);
+              $replacements[$original] = "99";
+              continue 2;
+            } else {
+
+              $replacements[$original] = $count_db['count'];
+            }
+          }
+
+          break;
+      }
+    }
+  }
+
+  // Return the replacements.
+  return $replacements;
+}
+
+/**
+ * Implements hook_tokens_alter().
+ * @param array $replacements
+ * @param array $context
+ * @param BubbleableMetadata $bubbleable_metadata
+ */
+function heartbeat_like_tokens_alter(array &$replacements, array $context, \Drupal\Core\Render\BubbleableMetadata $bubbleable_metadata) {
+
+  foreach ($replacements as $key => $replacement) {
+    if ($key === '[flagcount:count]' && $replacement == 0) {
+      $replacements[$key] = "";
+    }
+  }
+}

+ 26 - 0
heartbeat_like_comment/config/install/flag.flag.heartbeat_like_comment.yml

@@ -0,0 +1,26 @@
+langcode: en
+status: true
+dependencies:
+  module:
+    - heartbeat
+id: heartbeat_like_comment
+label: Heartbeat Like Comment
+entity_type: comment
+global: false
+weight: 0
+flag_short: 'Praise ([flagcount:count])'
+flag_long: ''
+flag_message: ''
+unflag_short: 'Reee ([flagcount:count])'
+unflag_long: ''
+unflag_message: ''
+unflag_denied_text: ''
+flag_type: 'entity:comment'
+link_type: ajax_link
+flagTypeConfig:
+  show_in_links: {  }
+  show_as_field: true
+  show_on_form: false
+  show_contextual_link: false
+  access_author: ''
+linkTypeConfig: {  }

+ 11 - 0
heartbeat_like_comment/heartbeat_like_comment.info.yml

@@ -0,0 +1,11 @@
+name : Heartbeat Like Comment
+type: module
+description : "Allows you to like Heartbeat Comments"
+dependencies:
+  - flag
+  - token
+  - heartbeat
+  - statusmessage
+
+core: '8.x'
+project: 'heartbeat'

+ 48 - 0
heartbeat_like_comment/heartbeat_like_comment.module

@@ -0,0 +1,48 @@
+<?php
+
+/**
+ * Implements hook_form_FORM_ID_alter().
+ * Tokenize the flag link strings.
+ */
+function heartbeat_like_comment_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
+
+  if ($form_id == 'flag_add_form' || $form_id == 'flag_edit_form')  {
+
+    // Setup for the "Browse available tokens" link.
+    $browse_array = array(
+      '#theme' => 'token_tree_link',
+      '#token_types' => array('heartbeat_like_comment'),
+    );
+
+    // Validation options to add to form elements.
+    $token_options = array(
+      '#element_validate' => array('token_element_validate'),
+      '#token_types' => array(),
+      '#min_tokens' => 1,
+      '#max_tokens' => 10,
+    );
+
+    // Let admin know that this field is now tokenized.
+    $form['messages']['flag_short']['#description'] .= '<br />' . t('This field supports tokens (try: "Like [flagcount:count]")');
+    $form['messages']['flag_short']['#suffix'] = render($browse_array);
+    $form['messages']['flag_short'] += $token_options;
+
+    $form['messages']['unflag_short']['#description'] .= '<br />' . t('This field supports tokens (try: "Unlike [flagcount:count]")');
+    $form['messages']['unflag_short']['#suffix'] = render($browse_array);
+    $form['messages']['unflag_short'] += $token_options;
+  }
+
+}
+
+/**
+ * Implements hook_preprocess_HOOK().
+ */
+function heartbeat_like_comment_preprocess_flag(&$variables) {
+
+  // Replace the link title with any tokens.
+  $token = Drupal::token();
+  $variables['title'] = $token->replace($variables['title'], array(
+    'flag_id' => $variables['flag']->id(),
+    'entity_id' => $variables['flaggable']->id(),
+  ));
+}

+ 70 - 0
heartbeat_like_comment/heartbeat_like_comment.tokens.inc

@@ -0,0 +1,70 @@
+<?php
+
+/**
+ * @file
+ * Token for heartbeat_like.
+ */
+
+use Drupal\Core\Render\BubbleableMetadata;
+
+/**
+ * Implements hook_token_info().
+ */
+function heartbeat_like_comment_token_info() {
+
+  $types = array();
+  $tokens = array();
+
+  // Flag tokens.
+  $types['flagcount'] = array(
+    'name' => t('Flags count'),
+    'description' => t('Tokens related to flag count (heartbeat_like_comment) module.'),
+  );
+  $tokens['flagcount']['count'] = array(
+    'name' => t('Count'),
+    'description' => t('Number of times the flag has been flagged.'),
+    'needs-data' => 'flag',
+  );
+
+  return array(
+    'types' => $types,
+    'tokens' => $tokens,
+  );
+}
+
+ /**
+  * Implements hook_tokens().
+  */
+function heartbeat_like_comment_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
+  $replacements = array();
+
+  if ($type == 'flagcount') {
+    foreach ($tokens as $name => $original) {
+      // Find the desired token by name
+      switch ($name) {
+        case 'count':
+
+          if (isset($data['flag_id']) && isset($data['entity_id'])) {
+
+            // Query the db for the count associated with this entity.
+            $query = \Drupal::database()->select('flag_counts', 'fc');
+            $query->fields('fc', ['count']);
+            $query->condition('fc.flag_id', $data['flag_id']);
+            $query->condition('fc.entity_id', $data['entity_id']);
+            $count_db = $query->execute()->fetchAssoc();
+
+            if (!isset($count_db['count'])) {
+              $count_db['count'] = 0;
+            }
+
+            $replacements[$original] = $count_db['count'];
+          }
+
+          break;
+      }
+    }
+  }
+
+  // Return the replacements.
+  return $replacements;
+}

+ 26 - 0
jihad_flag/config/install/flag.flag.jihad.yml

@@ -0,0 +1,26 @@
+langcode: en
+status: true
+dependencies:
+  module:
+    - heartbeat
+id: jihad_flag
+label: Jihad
+entity_type: heartbeat
+global: false
+weight: 0
+flag_short: 'Jihad ([flagcount:count])'
+flag_long: ''
+flag_message: ''
+unflag_short: 'Truce ([flagcount:count])'
+unflag_long: ''
+unflag_message: ''
+unflag_denied_text: ''
+flag_type: 'entity:heartbeat'
+link_type: ajax_link
+flagTypeConfig:
+  show_in_links: {  }
+  show_as_field: true
+  show_on_form: false
+  show_contextual_link: false
+  access_author: ''
+linkTypeConfig: {  }

+ 11 - 0
jihad_flag/jihad_flag.info.yml

@@ -0,0 +1,11 @@
+name : Jihad Flag
+type: module
+description : "Declare Meme Jihad on someone"
+dependencies:
+  - flag
+  - token
+  - heartbeat
+  - statusmessage
+
+core: '8.x'
+project: 'kekistan'

+ 48 - 0
jihad_flag/jihad_flag.module

@@ -0,0 +1,48 @@
+<?php
+
+/**
+ * Implements hook_form_FORM_ID_alter().
+ * Tokenize the flag link strings.
+ */
+function jihad_flag_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
+
+  if ($form_id == 'flag_add_form' || $form_id == 'flag_edit_form')  {
+
+    // Setup for the "Browse available tokens" link.
+    $browse_array = array(
+      '#theme' => 'token_tree_link',
+      '#token_types' => array('jihad_flag'),
+    );
+
+    // Validation options to add to form elements.
+    $token_options = array(
+      '#element_validate' => array('token_element_validate'),
+      '#token_types' => array(),
+      '#min_tokens' => 1,
+      '#max_tokens' => 10,
+    );
+
+    // Let admin know that this field is now tokenized.
+    $form['messages']['flag_short']['#description'] .= '<br />' . t('This field supports tokens (try: "Jihad [flagcount:count]")');
+    $form['messages']['flag_short']['#suffix'] = render($browse_array);
+    $form['messages']['flag_short'] += $token_options;
+
+    $form['messages']['unflag_short']['#description'] .= '<br />' . t('This field supports tokens (try: "Truce [flagcount:count]")');
+    $form['messages']['unflag_short']['#suffix'] = render($browse_array);
+    $form['messages']['unflag_short'] += $token_options;
+  }
+
+}
+
+/**
+ * Implements hook_preprocess_HOOK().
+ */
+function jihad_flag_preprocess_flag(&$variables) {
+
+  // Replace the link title with any tokens.
+  $token = Drupal::token();
+  $variables['title'] = $token->replace($variables['title'], array(
+    'flag_id' => $variables['flag']->id(),
+    'entity_id' => $variables['flaggable']->id(),
+  ));
+}

+ 70 - 0
jihad_flag/jihad_flag.tokens.inc

@@ -0,0 +1,70 @@
+<?php
+
+/**
+ * @file
+ * Token for jihad_flag.
+ */
+
+use Drupal\Core\Render\BubbleableMetadata;
+
+/**
+ * Implements hook_token_info().
+ */
+function jihad_flag_token_info() {
+
+  $types = array();
+  $tokens = array();
+
+  // Flag tokens.
+  $types['flagcount'] = array(
+    'name' => t('Flags count'),
+    'description' => t('Tokens related to flag count (jihad_flag) module.'),
+  );
+  $tokens['flagcount']['count'] = array(
+    'name' => t('Count'),
+    'description' => t('Number of times the flag has been flagged.'),
+    'needs-data' => 'flag',
+  );
+
+  return array(
+    'types' => $types,
+    'tokens' => $tokens,
+  );
+}
+
+ /**
+  * Implements hook_tokens().
+  */
+function jihad_flag_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
+  $replacements = array();
+
+  if ($type == 'flagcount') {
+    foreach ($tokens as $name => $original) {
+      // Find the desired token by name
+      switch ($name) {
+        case 'count':
+
+          if (isset($data['flag_id']) && isset($data['entity_id'])) {
+
+            // Query the db for the count associated with this entity.
+            $query = \Drupal::database()->select('flag_counts', 'fc');
+            $query->fields('fc', ['count']);
+            $query->condition('fc.flag_id', $data['flag_id']);
+            $query->condition('fc.entity_id', $data['entity_id']);
+            $count_db = $query->execute()->fetchAssoc();
+
+            if (!isset($count_db['count'])) {
+              $count_db['count'] = 0;
+            }
+
+            $replacements[$original] = $count_db['count'];
+          }
+
+          break;
+      }
+    }
+  }
+
+  // Return the replacements.
+  return $replacements;
+}