You are here

public function RssFields::render in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Plugin/views/row/RssFields.php \Drupal\views\Plugin\views\row\RssFields::render()

Render a row object. This usually passes through to a theme template of some form, but not always.

Parameters

object $row: A single row of the query result, so an element of $view->result.

Return value

string The rendered output of a single row, used by the style plugin.

Overrides RowPluginBase::render

File

core/modules/views/src/Plugin/views/row/RssFields.php, line 129
Contains \Drupal\views\Plugin\views\row\RssFields.

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;
  }
  if (function_exists('rdf_get_namespaces')) {

    // Merge RDF namespaces in the XML namespaces in case they are used
    // further in the RSS content.
    $xml_rdf_namespaces = array();
    foreach (rdf_get_namespaces() as $prefix => $uri) {
      $xml_rdf_namespaces['xmlns:' . $prefix] = $uri;
    }
    $this->view->style_plugin->namespaces += $xml_rdf_namespaces;
  }

  // Create the RSS item object.
  $item = new \stdClass();
  $item->title = $this
    ->getField($row_index, $this->options['title_field']);

  // @todo Views should expect and store a leading /. See:
  //   https://www.drupal.org/node/2423913
  $item->link = Url::fromUserInput('/' . $this
    ->getField($row_index, $this->options['link_field']))
    ->setAbsolute()
    ->toString();
  $field = $this
    ->getField($row_index, $this->options['description_field']);
  $item->description = is_array($field) ? $field : [
    '#markup' => $field,
  ];
  $item->elements = array(
    array(
      'key' => 'pubDate',
      'value' => $this
        ->getField($row_index, $this->options['date_field']),
    ),
    array(
      'key' => 'dc:creator',
      'value' => $this
        ->getField($row_index, $this->options['creator_field']),
      'namespace' => array(
        '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';

    // @todo Enforce GUIDs as system-generated rather than user input? See
    //   https://www.drupal.org/node/2430589.
    $item_guid = Url::fromUserInput('/' . $item_guid)
      ->setAbsolute()
      ->toString();
  }
  $item->elements[] = array(
    'key' => 'guid',
    'value' => $item_guid,
    'attributes' => array(
      '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 = array(
    '#theme' => $this
      ->themeFunctions(),
    '#view' => $this->view,
    '#options' => $this->options,
    '#row' => $item,
    '#field_alias' => isset($this->field_alias) ? $this->field_alias : '',
  );
  return $build;
}