Browse Source

FIX articoli senza body

root 4 years ago
parent
commit
13822ec957
1 changed files with 8 additions and 2 deletions
  1. 8 2
      src/Controller/CalendarRorController.php

+ 8 - 2
src/Controller/CalendarRorController.php

@@ -34,9 +34,15 @@ class CalendarRorController extends ControllerBase {
         $nodes_e = \Drupal\node\Entity\Node::loadMultiple($nids);
         $data['nodes'] =  array();
         foreach($nodes_e as $nid => $node) {
-            $data['nodes'][$nid] = $node->toArray();
+            $na = $node->toArray();
+            if(count($na['body']) > 0) { // c'e' gente che pubblica articoli senza body
+                $body = $na['body'][0]['value'];
+            } else {
+                $body = '';
+            }
+            $data['nodes'][$nid] =  $na;
             $data['nodes'][$nid]['summary'] = htmlspecialchars(substr(
-                html_entity_decode(strip_tags($data['nodes'][$nid]['body'][0]['value'])),
+                html_entity_decode(strip_tags($body)),
                 0, 3500), ENT_XML1, 'UTF-8');
         }