function RssFields::render

Same name in other branches
  1. 9 core/modules/views/src/Plugin/views/row/RssFields.php \Drupal\views\Plugin\views\row\RssFields::render()
  2. 8.9.x core/modules/views/src/Plugin/views/row/RssFields.php \Drupal\views\Plugin\views\row\RssFields::render()
  3. 10 core/modules/views/src/Plugin/views/row/RssFields.php \Drupal\views\Plugin\views\row\RssFields::render()

Overrides RowPluginBase::render

File

core/modules/views/src/Plugin/views/row/RssFields.php, line 125

Class

RssFields
Renders an RSS item based on fields.

Namespace

Drupal\views\Plugin\views\row

Code

public function render($row) {
    static $row_index;
    if (!isset($row_index)) {
        $row_index = 0;
    }
    // Create the RSS item object.
    $item = new \stdClass();
    $item->title = $this->getField($row_index, $this->options['title_field']);
    $item->link = $this->getAbsoluteUrl($this->getField($row_index, $this->options['link_field']));
    $field = $this->getField($row_index, $this->options['description_field']);
    $item->description = is_array($field) ? $field : [
        '#markup' => $field,
    ];
    $item->elements = [
        // Default rendering of date fields adds a <time> tag and whitespace, we
        // want to remove these because this breaks RSS feeds.
[
            'key' => 'pubDate',
            'value' => trim(strip_tags($this->getField($row_index, $this->options['date_field']))),
        ],
        [
            'key' => 'dc:creator',
            'value' => $this->getField($row_index, $this->options['creator_field']),
            'namespace' => [
                'xmlns:dc' => 'http://purl.org/dc/elements/1.1/',
            ],
        ],
    ];
    $guid_is_permalink_string = 'false';
    $item_guid = $this->getField($row_index, $this->options['guid_field_options']['guid_field']);
    if ($this->options['guid_field_options']['guid_field_is_permalink']) {
        $guid_is_permalink_string = 'true';
        $item_guid = $this->getAbsoluteUrl($item_guid);
    }
    $item->elements[] = [
        'key' => 'guid',
        'value' => $item_guid,
        'attributes' => [
            'isPermaLink' => $guid_is_permalink_string,
        ],
    ];
    $row_index++;
    foreach ($item->elements as $element) {
        if (isset($element['namespace'])) {
            $this->view->style_plugin->namespaces = array_merge($this->view->style_plugin->namespaces, $element['namespace']);
        }
    }
    $build = [
        '#theme' => $this->themeFunctions(),
        '#view' => $this->view,
        '#options' => $this->options,
        '#row' => $item,
        '#field_alias' => $this->field_alias ?? '',
    ];
    return $build;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.