You are here

public function RssFields::render in Podcast (using Views) 8

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 RssFields::render

File

src/Plugin/views/row/RssFields.php, line 143

Class

RssFields
Renders an RSS item based on fields.

Namespace

Drupal\podcast\Plugin\views\row

Code

public function render($row) {
  static $row_index;
  if (!isset($row_index)) {
    $row_index = 0;
  }
  $build = parent::render($row);
  $item = $build['#row'];
  $description = $this
    ->buildElementFromOptions('description', $row_index);
  $item->description = NestedArray::getValue($description, [
    'value',
  ]);
  $keyval_url = $this
    ->buildElementForLink(NULL, $row_index, [
    'enclosure_field_options',
    'enclosure_field_url',
  ]);
  $keyval_length = $this
    ->buildElementFromOptions(NULL, $row_index, [
    'enclosure_field_options',
    'enclosure_field_length',
  ]);
  $keyval_type = $this
    ->buildElementFromOptions(NULL, $row_index, [
    'enclosure_field_options',
    'enclosure_field_type',
  ]);
  $item->elements[] = [
    'key' => 'itunes:image',
    'attributes' => [
      'href' => $this
        ->buildElementFromOptions(NULL, $row_index, [
        'itunes:image_field',
      ]),
    ],
  ];
  $item->elements[] = [
    'key' => 'enclosure',
    'attributes' => [
      'url' => NestedArray::getValue($keyval_url, [
        'value',
      ]),
      'length' => NestedArray::getValue($keyval_length, [
        'value',
      ]),
      'type' => NestedArray::getValue($keyval_type, [
        'value',
      ]),
    ],
  ];
  $item->elements[] = $this
    ->buildElementFromOptions('itunes:title', $row_index, [
    'title_field',
  ]);
  $link_keys = [
    'link',
  ];
  $item->elements = array_reduce($link_keys, function ($elements, $key) use ($row_index) {
    return array_merge($elements, [
      $this
        ->buildElementForLink($key, $row_index),
    ]);
  }, $item->elements);
  $keys = [
    'description',
    'itunes:author',
    'itunes:keywords',
    'itunes:explicit',
    'itunes:duration',
    'itunes:summary',
    'itunes:season',
    'itunes:episode',
  ];
  $item->elements = array_reduce($keys, function ($elements, $key) use ($row_index) {
    return array_merge($elements, [
      $this
        ->buildElementFromOptions($key, $row_index),
    ]);
  }, $item->elements);
  $item->elements = array_filter($item->elements);
  $build['#row'] = $item;
  $row_index++;
  return $build;
}