function views_rss_format_preprocess_views_view_row_rss in Views RSS 8.2
Same name and namespace in other branches
- 8.3 modules/views_rss_format/views_rss_format.module \views_rss_format_preprocess_views_view_row_rss()
Prepares variables for views RSS item templates.
Default template: views-view-row-rss.html.twig.
Parameters
array $variables: An associative array containing:
- row: The raw results rows.
See also
template_preprocess_views_view_row_rss()
File
- modules/
views_rss_format/ views_rss_format.module, line 25 - Provides custom version of format_xml_elements() function allowing to skip special character encoding in selected XML element values and relevant template_preprocess_views_view_row_rss() implementation.
Code
function views_rss_format_preprocess_views_view_row_rss(&$variables) {
$item = $variables['row'];
$variables['title'] = $item->title;
if (isset($item->link)) {
$variables['link'] = UrlHelper::stripDangerousProtocols($item->link);
}
else {
$variables['link'] = '';
}
// The description is the only place where we should find HTML.
// @see https://validator.w3.org/feed/docs/rss2.html#hrelementsOfLtitemgt
// If we have a render array, render it here and pass the result to the
// template, letting Twig autoescape it.
if (isset($item->description)) {
$variables['description'] = $item->description;
//$variables['description'] = (string) \Drupal::service('renderer')->render($item->description);
}
$variables['item_elements'] = [];
foreach ($item->elements as $element) {
if (isset($element['attributes']) && is_array($element['attributes'])) {
$element['attributes'] = new Attribute($element['attributes']);
}
$variables['item_elements'][] = $element;
}
}