views_rss_format.module in Views RSS 8.2
Same filename and directory in other branches
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.
File
modules/views_rss_format/views_rss_format.moduleView source
<?php
/**
* @file
* 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.
*/
use Drupal\Component\Utility\Html;
use Drupal\Core\Template\Attribute;
use Drupal\Component\Utility\UrlHelper;
/**
* Prepares variables for views RSS item templates.
*
* Default template: views-view-row-rss.html.twig.
*
* @param array $variables
* An associative array containing:
* - row: The raw results rows.
*
* @see template_preprocess_views_view_row_rss()
*/
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;
}
}
Functions
Name | Description |
---|---|
views_rss_format_preprocess_views_view_row_rss | Prepares variables for views RSS item templates. |