template_preprocess_views_view_rss(&$variables)
Prepares variables for RSS feed templates.
Default template: views-view-rss.html.twig.
Parameters
array $variables: An associative array containing:
- view: A ViewExecutable object.
- rows: The raw row data.
File
- core/modules/views/views.theme.inc, line 835
- Preprocessors and helper functions to make theming easier.
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | function template_preprocess_views_view_rss(& $variables ) { $view = $variables [ 'view' ]; $items = $variables [ 'rows' ]; $style = $view ->style_plugin; $config = \Drupal::config( 'system.site' ); // The RSS 2.0 "spec" doesn't indicate HTML can be used in the description. // We strip all HTML tags, but need to prevent double encoding from properly // escaped source data (such as & becoming &amp;). $variables [ 'description' ] = Html::decodeEntities( strip_tags ( $style ->getDescription())); if ( $view ->display_handler->getOption( 'sitename_title' )) { $title = $config ->get( 'name' ); if ( $slogan = $config ->get( 'slogan' )) { $title .= ' - ' . $slogan ; } } else { $title = $view ->getTitle(); } $variables [ 'title' ] = $title ; // Figure out which display which has a path we're using for this feed. If // there isn't one, use the global $base_url $link_display_id = $view ->display_handler->getLinkDisplay(); if ( $link_display_id && $display = $view ->displayHandlers->get( $link_display_id )) { $url = $view ->getUrl(NULL, $link_display_id ); } /** @var \Drupal\Core\Url $url */ if ( $url ) { $url_options = array ( 'absolute' => TRUE); if (! empty ( $view ->exposed_raw_input)) { $url_options [ 'query' ] = $view ->exposed_raw_input; } // Compare the link to the default home page; if it's the default home page, // just use $base_url. $url_string = $url ->setOptions( $url_options )->toString(); if ( $url_string === Url::fromUserInput( $config ->get( 'page.front' ))->toString()) { $url_string = Url::fromRoute( '<front>' )->setAbsolute()->toString(); } $variables [ 'link' ] = $url_string ; } $variables [ 'langcode' ] = \Drupal::languageManager()->getCurrentLanguage()->getId(); $variables [ 'namespaces' ] = new Attribute( $style ->namespaces); $variables [ 'items' ] = $items ; $variables [ 'channel_elements' ] = \Drupal::service( 'renderer' )->render( $style ->channel_elements); // During live preview we don't want to output the header since the contents // of the feed are being displayed inside a normal HTML page. if ( empty ( $variables [ 'view' ]->live_preview)) { $variables [ 'view' ]->getResponse()->headers->set( 'Content-Type' , 'application/rss+xml; charset=utf-8' ); } } |
Please login to continue.