You are here

public function OpmlFields::render in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/src/Plugin/views/row/OpmlFields.php \Drupal\views\Plugin\views\row\OpmlFields::render()
  2. 10 core/modules/views/src/Plugin/views/row/OpmlFields.php \Drupal\views\Plugin\views\row\OpmlFields::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/OpmlFields.php, line 172

Class

OpmlFields
Renders an OPML item based on fields.

Namespace

Drupal\views\Plugin\views\row

Code

public function render($row) {

  // Create the OPML item array.
  $item = [];
  $row_index = $this->view->row_index;
  $item['text'] = $this
    ->getField($row_index, $this->options['text_field']);
  $item['created'] = $this
    ->getField($row_index, $this->options['created_field']);
  if ($this->options['type_field']) {
    $item['type'] = $this->options['type_field'];
    if ($item['type'] == 'rss') {
      $item['description'] = $this
        ->getField($row_index, $this->options['description_field']);
      $item['language'] = $this
        ->getField($row_index, $this->options['language_field']);
      $item['xmlUrl'] = $this
        ->getField($row_index, $this->options['xml_url_field']);
      $item['htmlUrl'] = $this
        ->getField($row_index, $this->options['html_url_field']);
    }
    else {
      $item['url'] = $this
        ->getField($row_index, $this->options['url_field']);
    }
  }

  // Remove empty attributes.
  $item = array_filter($item);
  $build = [
    '#theme' => $this
      ->themeFunctions(),
    '#view' => $this->view,
    '#options' => $this->options,
    '#row' => $item,
    '#field_alias' => isset($this->field_alias) ? $this->field_alias : '',
  ];
  return $build;
}