You are here

function template_preprocess_views_view_row_rss in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views/views.theme.inc \template_preprocess_views_view_row_rss()
  2. 9 core/modules/views/views.theme.inc \template_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.

File

core/modules/views/views.theme.inc, line 941
Preprocessors and helper functions to make theming easier.

Code

function template_preprocess_views_view_row_rss(&$variables) {
  $item = $variables['row'];
  $variables['title'] = $item->title;
  $variables['link'] = $item->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) && is_array($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;
  }
}