FIX articoli senza body

This commit is contained in:
root 2019-08-04 19:40:57 +02:00
parent a1616ea461
commit 13822ec957

View file

@ -34,9 +34,15 @@ class CalendarRorController extends ControllerBase {
$nodes_e = \Drupal\node\Entity\Node::loadMultiple($nids); $nodes_e = \Drupal\node\Entity\Node::loadMultiple($nids);
$data['nodes'] = array(); $data['nodes'] = array();
foreach($nodes_e as $nid => $node) { 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( $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'); 0, 3500), ENT_XML1, 'UTF-8');
} }