You are here

protected function Rss::getPodcastElements in Podcast (using Views) 8

Return an array of additional XHTML elements to add to the podcast channel.

Return value

array A keyval array.

1 call to Rss::getPodcastElements()
Rss::render in src/Plugin/views/style/Rss.php
Render the display in this style.

File

src/Plugin/views/style/Rss.php, line 222

Class

Rss
Default style plugin to render an RSS feed.

Namespace

Drupal\podcast\Plugin\views\style

Code

protected function getPodcastElements() {
  $podcast_elements = [];
  $image_field_value = $this
    ->getField(0, $this->options['itunes:image_field']);
  $image_url = UrlHelper::isExternal($image_field_value) ? $image_field_value : \Drupal::request()
    ->getSchemeAndHttpHost() . $image_field_value;
  $parsed_image_field = parse_url($image_url);
  $podcast_elements[] = [
    'key' => 'itunes:image',
    'value' => '',
    'attributes' => [
      'href' => $image_url,
    ],
  ];
  $podcast_elements[] = [
    'key' => 'image',
    'attributes' => [],
    'values' => [
      [
        'key' => 'url',
        'value' => $image_url,
      ],
      [
        'key' => 'link',
        'value' => $parsed_image_field['scheme'] . '://' . $parsed_image_field['host'] . (!empty($parsed_image_field['port']) ? ':' . $parsed_image_field['port'] : ''),
      ],
      [
        'key' => 'title',
        'value' => $this
          ->getField(0, $this->options['title_field']),
      ],
    ],
  ];
  $podcast_elements[] = [
    'key' => 'generator',
    'value' => $this->options['generator'],
  ];
  $podcast_elements[] = [
    'key' => 'copyright',
    'value' => $this->options['copyright'],
  ];
  $keys = [
    'title',
    'description',
    'lastBuildDate',
    'author',
    'itunes:explicit',
    'itunes:author',
    'itunes:summary',
    'itunes:keywords',
  ];
  $podcast_elements = array_merge(array_map([
    $this,
    'buildElementFromOptions',
  ], $keys), $podcast_elements);
  $owner_name = $this
    ->getField(0, $this->options['itunes:owner--name_field']);
  $owner_email = $this
    ->getField(0, $this->options['itunes:owner--email_field']);
  if (!empty($owner_email) || !empty($owner_name)) {
    $podcast_elements[] = [
      'key' => 'itunes:owner',
      'values' => [
        [
          'key' => 'itunes:name',
          'value' => $owner_name,
        ],
        [
          'key' => 'itunes:email',
          'value' => $owner_email,
        ],
      ],
    ];
  }
  $link_keys = [
    'link',
    'itunes:new-feed-url',
  ];
  $podcast_elements = array_reduce($link_keys, function ($elements, $key) {
    return array_merge($elements, [
      $this
        ->buildElementForLink($key),
    ]);
  }, $podcast_elements);
  $categories = $this
    ->buildElementFromOptions('itunes:category');
  if (!empty($categories)) {
    $category_elements = $this
      ->processCategories($categories);
    $podcast_elements = array_merge($podcast_elements, $category_elements);
  }
  return $podcast_elements;
}