heartbeat8.module 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * @file
  4. * Contains heartbeat8.module.
  5. */
  6. use Drupal\Core\Routing\RouteMatchInterface;
  7. use Drupal\Heartbeat8\Entity\Heartbeat;
  8. //TODO add constants (HEARTBEAT_NONE, HEARTBEAT_PRIVATE, HEARTBEAT_PUBLIC_TO_ADDRESSEE, HEARTBEAT_PUBLIC_TO_ALL_CONNECTED, HEARTBEAT_PUBLIC_TO_ALL)
  9. //TODO include Streams (Entities already added with use statements on lines 9-10)
  10. /**
  11. * Implements hook_help().
  12. */
  13. function heartbeat8_help($route_name, RouteMatchInterface $route_match) {
  14. switch ($route_name) {
  15. // Main module help for the heartbeat8 module.
  16. case 'help.page.heartbeat8':
  17. $output = '';
  18. $output .= '<h3>' . t('About') . '</h3>';
  19. $output .= '<p>' . t('Heartbeat for Drupal 8') . '</p>';
  20. return $output;
  21. default:
  22. }
  23. }
  24. /**
  25. * Implements hook_theme().
  26. */
  27. function heartbeat8_theme() {
  28. $theme = [];
  29. $theme['heartbeat'] = array(
  30. 'render element' => 'elements',
  31. 'file' => 'heartbeat.page.inc',
  32. 'template' => 'heartbeat',
  33. );
  34. $theme['heartbeat_content_add_list'] = [
  35. 'render element' => 'content',
  36. 'variables' => ['content' => NULL],
  37. 'file' => 'heartbeat.page.inc',
  38. ];
  39. return $theme;
  40. }
  41. /**
  42. * Implements hook_theme_suggestions_HOOK().
  43. */
  44. function heartbeat8_theme_suggestions_heartbeat(array $variables) {
  45. $suggestions = array();
  46. $entity = $variables['elements']['#heartbeat'];
  47. $sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
  48. $suggestions[] = 'heartbeat__' . $sanitized_view_mode;
  49. $suggestions[] = 'heartbeat__' . $entity->bundle();
  50. $suggestions[] = 'heartbeat__' . $entity->bundle() . '__' . $sanitized_view_mode;
  51. $suggestions[] = 'heartbeat__' . $entity->id();
  52. $suggestions[] = 'heartbeat__' . $entity->id() . '__' . $sanitized_view_mode;
  53. return $suggestions;
  54. }
  55. //TODO Add heartbeat language to Javascript
  56. //TODO Determine necessity of polling
  57. //Add