heartbeat8.module 2.8 KB

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