heartbeat.page.inc 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * @file
  4. * Contains heartbeat.page.inc.
  5. *
  6. * Page callback for Heartbeat entities.
  7. */
  8. use Drupal\Core\Render\Element;
  9. /**
  10. * Prepares variables for Heartbeat templates.
  11. *
  12. * Default template: heartbeat.html.twig.
  13. *
  14. * @param array $variables
  15. * An associative array containing:
  16. * - elements: An associative array containing the user information and any
  17. * - attributes: HTML attributes for the containing element.
  18. */
  19. function template_preprocess_heartbeat(array &$variables) {
  20. // Fetch Heartbeat Entity Object.
  21. $entity = $variables['elements']['#heartbeat'];
  22. if ($entity->getEntityType() == 'heartbeat' && $entity->isPublished()) {
  23. $node = \Drupal::entityTypeManager()
  24. ->getStorage('node')
  25. ->load($entity->getNid()->getValue()[0]['target_id']);
  26. if ($node !== null) {
  27. $renderedNode = \Drupal::entityTypeManager()->getViewBuilder('node')->view($node, 'full');
  28. $variables['content']['node'] = $renderedNode;
  29. }
  30. }
  31. // Helpful $content variable for templates.
  32. foreach (Element::children($variables['elements']) as $key) {
  33. $variables['content'][$key] = $variables['elements'][$key];
  34. }
  35. }