heartbeat8.module 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * @file
  4. * Contains heartbeat8.module.
  5. */
  6. use Drupal\Core\Routing\RouteMatchInterface;
  7. use Drupal\Core\Entity\EntityInterface;
  8. use Drupal\node\NodeInterface;
  9. use Drupal\Core\Session\AccountInterface;
  10. use Drupal\Core\Entity;
  11. use Drupal\heartbeat8\Entity\Heartbeat;
  12. use Drupal\heartbeat8\Entity\HeartbeatType;
  13. //TODO include Streams (Entities already added with use statements on lines 9-10)
  14. // Always block from display
  15. const HEARTBEAT_NONE = -1;
  16. // Display only activity messages that are mine or addressed to me
  17. const HEARTBEAT_PRIVATE = 0;
  18. // Only the person that is chosen by the actor, can see the message
  19. const HEARTBEAT_PUBLIC_TO_ADDRESSEE = 1;
  20. // Display activity message of all my user relations, described in contributed modules
  21. const HEARTBEAT_PUBLIC_TO_CONNECTED = 2;
  22. // Everyone can see this activity message, unless this type of message is set to private
  23. const HEARTBEAT_PUBLIC_TO_ALL = 4;
  24. //Group Types
  25. const HEARTBEAT_GROUP_NONE = 11;
  26. const HEARTBEAT_GROUP_SINGLE = 12;
  27. const HEARTBEAT_GROUP_SUMMARY = 13;
  28. /**
  29. * Implements hook_help().
  30. */
  31. function heartbeat8_help($route_name, RouteMatchInterface $route_match) {
  32. switch ($route_name) {
  33. // Main module help for the heartbeat8 module.
  34. case 'help.page.heartbeat8':
  35. $output = '';
  36. $output .= '<h3>' . t('About') . '</h3>';
  37. $output .= '<p>' . t('Heartbeat for Drupal 8') . '</p>';
  38. return $output;
  39. default:
  40. }
  41. }
  42. /**
  43. * Implements hook_theme().
  44. */
  45. function heartbeat8_theme() {
  46. $theme = [];
  47. $theme['heartbeat'] = array(
  48. 'render element' => 'elements',
  49. 'file' => 'heartbeat.page.inc',
  50. 'template' => 'heartbeat',
  51. );
  52. $theme['heartbeat_content_add_list'] = [
  53. 'render element' => 'content',
  54. 'variables' => ['content' => NULL],
  55. 'file' => 'heartbeat.page.inc',
  56. ];
  57. return $theme;
  58. }
  59. /**
  60. * Implements hook_theme_suggestions_HOOK().
  61. */
  62. function heartbeat8_theme_suggestions_heartbeat(array $variables) {
  63. $suggestions = array();
  64. $entity = $variables['elements']['#heartbeat'];
  65. $sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
  66. $suggestions[] = 'heartbeat__' . $sanitized_view_mode;
  67. $suggestions[] = 'heartbeat__' . $entity->bundle();
  68. $suggestions[] = 'heartbeat__' . $entity->bundle() . '__' . $sanitized_view_mode;
  69. $suggestions[] = 'heartbeat__' . $entity->id();
  70. $suggestions[] = 'heartbeat__' . $entity->id() . '__' . $sanitized_view_mode;
  71. return $suggestions;
  72. }
  73. /**
  74. * Implements hook_entity_insert().
  75. */
  76. function heartbeat8_entity_insert(EntityInterface $entity) {
  77. $thisiswhere = 'ithappens';
  78. $nid = $entity->id();
  79. if ($nid) {
  80. $heartbeatTypeService = \Drupal::service('heartbeat8.heartbeattype');
  81. foreach ($heartbeatTypeService->getTypes() as $type) {
  82. $heartbeatTypeEntity = \Drupal::entityTypeManager()->getStorage('heartbeat_type')->load($type);
  83. }
  84. }
  85. \Drupal::logger('content')->notice('Entity Insert
  86. called !');
  87. }
  88. //TODO Add heartbeat language to Javascript
  89. //TODO Determine necessity of polling
  90. //Add