state = $state; $this->twig = $twig; } public static function create(ContainerInterface $container) { return new static( $container->get('state'), $container->get('twig') ); } private function query($baseQuery) { //TODO: estrai argomento dall'url $arg = array('ror_news', 'redazionali', 'news_trasmissioni'); $query = $baseQuery ->condition('status', '1') ->condition('type', $arg, 'IN') ->sort('nid', 'DESC') ->range(0, 20); \Drupal::logger('podcast_ror')->info(var_export(\Drupal::request()->query->get('trxid'), true)); //$trxid = \Drupal::request()->query->get('trxid'); // TODO: se nell'url c'e' un trx=, allora bisogna // aggiungere che arg=news_trasmissioni // fare join con node__field_trasmissione ON // node.nid = node__field_trasmissione.entity_id // condition: node__field_trasmissione.field_trasmissione_target_id=$trx $nids = $query->execute(); // TODO: load contenuti_audio referenced entities $data = array(); $nodes_e = \Drupal\node\Entity\Node::loadMultiple($nids); $data['nodes'] = array(); foreach($nodes_e as $nid => $node) { $data['nodes'][$nid] = $node->toArray(); $data['nodes'][$nid]['summary'] = htmlspecialchars(substr( html_entity_decode(strip_tags($data['nodes'][$nid]['body'][0]['value'])), 0, 3500), ENT_XML1, 'UTF-8'); } $first = true; foreach($nodes_e as $nid => $node) { $data['nodes'][$nid]['audio'] = array(); $data['nodes'][$nid]['img'] = array(); foreach( $node->get('field_contenuti_audio')->referencedEntities() as $ai => $entity) { $data['nodes'][$nid]['audio'][$ai] = $entity->toArray(); //$data['nodes'][$nid]['audio'][$ai]['text'] = print_r($data['nodes'][$nid]['audio'][$ai]['field_audio_link'], true); } foreach( $node->get('field_image')->referencedEntities() as $ai => $entity) { $arr = $entity->toArray(); $data['nodes'][$nid]['img'][] = array( 'uri' => file_create_url($arr['uri'][0]['value']), // 'raw' => $arr, ); } if($first === true) { // print_r($data['nodes'][$nid]['img']); $first = false; } } return $data; } public function podcast($query) { $template = $this->twig->loadTemplate(drupal_get_path('module', 'podcast_ror') . '/templates/podcast.html.twig'); $tmpl_data = [ 'ror' => array('podcast' => $this->query($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; } public function podcastAll() { $query = \Drupal::entityQuery('node'); return $this->podcast($query); } //public function podcastByType(NodeInterface $ctype) { public function podcastByType($contentType) { $query = \Drupal::entityQuery('node') ->condition('type', $contentType); return $this->podcast($query); } public function podcastByTrxID($trxID) { $query = \Drupal::entityQuery('node') ->condition('type', 'news_trasmissioni') ->condition('field_trasmissione', $trxID); return $this->podcast($query); } }