Parcourir la source

Adding logic to render associated node with each heartbeat. This is only visible on the heartbeat page or heartbeat stream pages. Main feed on front page uses higher performance message

logicp il y a 7 ans
Parent
commit
042ab32d60
3 fichiers modifiés avec 17 ajouts et 9 suppressions
  1. 15 4
      heartbeat.page.inc
  2. 2 4
      templates/heartbeat.html.twig
  3. 0 1
      templates/heartbeat_stream.html.twig

+ 15 - 4
heartbeat.page.inc

@@ -21,10 +21,21 @@ use Drupal\Core\Render\Element;
  */
 function template_preprocess_heartbeat(array &$variables) {
   // Fetch Heartbeat Entity Object.
-  $heartbeat = $variables['elements']['#heartbeat'];
+  $entity = $variables['elements']['#heartbeat'];
 
-  // Helpful $content variable for templates.
-  foreach (Element::children($variables['elements']) as $key) {
-    $variables['content'][$key] = $variables['elements'][$key];
+  if ($entity->isPublished()) {
+    $node = \Drupal::entityTypeManager()
+      ->getStorage('node')
+      ->load($entity->getNid()->getValue()[0]['target_id']);
+
+    if ($node !== null) {
+      $renderedNode = \Drupal::entityTypeManager()->getViewBuilder('node')->view($node, 'full');
+      $variables['content']['node'] = $renderedNode;
+    }
+
+    // Helpful $content variable for templates.
+    foreach (Element::children($variables['elements']) as $key) {
+      $variables['content'][$key] = $variables['elements'][$key];
+    }
   }
 }

+ 2 - 4
templates/heartbeat.html.twig

@@ -17,9 +17,7 @@
 #}
 <div{{ attributes.addClass('heartbeat') }}>
   {% if content %}
-    {{- content -}}
-    {% autoescape false %}
-      {{ content.message | raw }}
-    {% endautoescape %}
+    {{- content.message -}}
+    {{- content.node -}}
   {% endif %}
 </div>

+ 0 - 1
templates/heartbeat_stream.html.twig

@@ -18,6 +18,5 @@
 <div{{ attributes.addClass('heartbeat_stream') }}>
   {% if content %}
     {{- content -}}
-    <h1> The Jiggaman Cometh </h1>
   {% endif %}
 </div>