function template_preprocess_views_view_rss in Drupal 9
Same name and namespace in other branches
- 8 core/modules/views/views.theme.inc \template_preprocess_views_view_rss()
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 866 - Preprocessors and helper functions to make theming easier.
Code
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 &).
$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;
$variables['link'] = Url::fromRoute('<front>')
->setAbsolute()
->toString();
$variables['langcode'] = \Drupal::languageManager()
->getCurrentLanguage()
->getId();
$variables['namespaces'] = new Attribute($style->namespaces);
$variables['items'] = $items;
$variables['channel_elements'] = $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');
}
}