state = $state; $this->twig = $twig; } public static function create(ContainerInterface $container) { return new static( $container->get('state'), $container->get('twig') ); } private function query() { $query = \Drupal::entityQuery('node'); $query ->condition('status', '1') ->condition('type', 'eventi') ->sort('nid', 'DESC') ->range(0, 20); $nids = $query->execute(); $data = array(); $nodes_e = \Drupal\node\Entity\Node::loadMultiple($nids); $data['nodes'] = array(); foreach($nodes_e as $nid => $node) { $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($body)), 0, 3500), ENT_XML1, 'UTF-8'); } return $data; } public function ics() { // TODO: use $path $template = $this->twig->loadTemplate(drupal_get_path('module', 'calendar_ror') . '/templates/calendar.ics.twig'); $tmpl_data = [ 'ror' => array('calendar' => $this->query(), 'url' => \Drupal::service('path.current')->getPath(), )]; //$variables['ror']['url'] = $xml = $template->render($tmpl_data); $resp = new Response($xml, 200, array( 'Content-Type' => 'application/rss+xml')); return $resp; } }