heartbeat8.module 1.9 KB

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