1. 8.5.x core/modules/comment/src/Plugin/views/row/Rss.php
  2. 8.5.x core/modules/aggregator/src/Plugin/views/row/Rss.php
  3. 8.5.x vendor/zendframework/zend-feed/src/Writer/Renderer/Feed/Rss.php
  4. 8.5.x core/modules/views/src/Plugin/views/style/Rss.php
  5. 8.5.x vendor/zendframework/zend-feed/src/Reader/Entry/Rss.php
  6. 8.5.x vendor/zendframework/zend-feed/src/Writer/Renderer/Entry/Rss.php
  7. 8.5.x vendor/zendframework/zend-feed/src/Reader/Feed/Rss.php
  8. 8.5.x core/modules/node/src/Plugin/views/row/Rss.php
  9. 8.0.x core/modules/views/src/Plugin/views/style/Rss.php
  10. 8.0.x core/modules/aggregator/src/Plugin/views/row/Rss.php
  11. 8.0.x vendor/zendframework/zend-feed/src/Writer/Renderer/Feed/Rss.php
  12. 8.0.x core/modules/comment/src/Plugin/views/row/Rss.php
  13. 8.0.x core/modules/node/src/Plugin/views/row/Rss.php
  14. 8.0.x vendor/zendframework/zend-feed/src/Writer/Renderer/Entry/Rss.php
  15. 8.0.x vendor/zendframework/zend-feed/src/Reader/Feed/Rss.php
  16. 8.0.x vendor/zendframework/zend-feed/src/Reader/Entry/Rss.php
  17. 8.1.x core/modules/node/src/Plugin/views/row/Rss.php
  18. 8.1.x core/modules/views/src/Plugin/views/style/Rss.php
  19. 8.1.x core/modules/comment/src/Plugin/views/row/Rss.php
  20. 8.1.x core/modules/aggregator/src/Plugin/views/row/Rss.php
  21. 8.1.x vendor/zendframework/zend-feed/src/Writer/Renderer/Entry/Rss.php
  22. 8.1.x vendor/zendframework/zend-feed/src/Reader/Entry/Rss.php
  23. 8.1.x vendor/zendframework/zend-feed/src/Reader/Feed/Rss.php
  24. 8.1.x vendor/zendframework/zend-feed/src/Writer/Renderer/Feed/Rss.php
  25. 8.2.x core/modules/views/src/Plugin/views/style/Rss.php
  26. 8.2.x vendor/zendframework/zend-feed/src/Reader/Feed/Rss.php
  27. 8.2.x vendor/zendframework/zend-feed/src/Reader/Entry/Rss.php
  28. 8.2.x vendor/zendframework/zend-feed/src/Writer/Renderer/Entry/Rss.php
  29. 8.2.x vendor/zendframework/zend-feed/src/Writer/Renderer/Feed/Rss.php
  30. 8.2.x core/modules/node/src/Plugin/views/row/Rss.php
  31. 8.2.x core/modules/comment/src/Plugin/views/row/Rss.php
  32. 8.2.x core/modules/aggregator/src/Plugin/views/row/Rss.php
  33. 8.3.x core/modules/comment/src/Plugin/views/row/Rss.php
  34. 8.3.x core/modules/views/src/Plugin/views/style/Rss.php
  35. 8.3.x vendor/zendframework/zend-feed/src/Writer/Renderer/Entry/Rss.php
  36. 8.3.x core/modules/aggregator/src/Plugin/views/row/Rss.php
  37. 8.3.x vendor/zendframework/zend-feed/src/Reader/Feed/Rss.php
  38. 8.3.x vendor/zendframework/zend-feed/src/Reader/Entry/Rss.php
  39. 8.3.x vendor/zendframework/zend-feed/src/Writer/Renderer/Feed/Rss.php
  40. 8.3.x core/modules/node/src/Plugin/views/row/Rss.php
  41. 8.4.x core/modules/node/src/Plugin/views/row/Rss.php
  42. 8.4.x core/modules/comment/src/Plugin/views/row/Rss.php
  43. 8.4.x vendor/zendframework/zend-feed/src/Reader/Entry/Rss.php
  44. 8.4.x vendor/zendframework/zend-feed/src/Reader/Feed/Rss.php
  45. 8.4.x core/modules/aggregator/src/Plugin/views/row/Rss.php
  46. 8.4.x vendor/zendframework/zend-feed/src/Writer/Renderer/Feed/Rss.php
  47. 8.4.x vendor/zendframework/zend-feed/src/Writer/Renderer/Entry/Rss.php
  48. 8.4.x core/modules/views/src/Plugin/views/style/Rss.php
  49. 8.6.x core/modules/views/src/Plugin/views/style/Rss.php
  50. 8.6.x vendor/zendframework/zend-feed/src/Writer/Renderer/Feed/Rss.php
  51. 8.6.x core/modules/node/src/Plugin/views/row/Rss.php
  52. 8.6.x vendor/zendframework/zend-feed/src/Writer/Renderer/Entry/Rss.php
  53. 8.6.x core/modules/aggregator/src/Plugin/views/row/Rss.php
  54. 8.6.x vendor/zendframework/zend-feed/src/Reader/Entry/Rss.php
  55. 8.6.x vendor/zendframework/zend-feed/src/Reader/Feed/Rss.php
  56. 8.6.x core/modules/comment/src/Plugin/views/row/Rss.php

Namespace

Drupal\views\Plugin\views\style

File

core/modules/views/src/Plugin/views/style/Rss.php
View source
<?php

namespace Drupal\views\Plugin\views\style;

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;

/**
 * Default style plugin to render an RSS feed.
 *
 * @ingroup views_style_plugins
 *
 * @ViewsStyle(
 *   id = "rss",
 *   title = @Translation("RSS Feed"),
 *   help = @Translation("Generates an RSS feed from a view."),
 *   theme = "views_view_rss",
 *   display_types = {"feed"}
 * )
 */
class Rss extends StylePluginBase {

  /**
   * Does the style plugin for itself support to add fields to it's output.
   *
   * @var bool
   */
  protected $usesRowPlugin = TRUE;
  public function attachTo(array &$build, $display_id, Url $feed_url, $title) {
    $url_options = array();
    $input = $this->view
      ->getExposedInput();
    if ($input) {
      $url_options['query'] = $input;
    }
    $url_options['absolute'] = TRUE;
    $url = $feed_url
      ->setOptions($url_options)
      ->toString();

    // Add the RSS icon to the view.
    $this->view->feedIcons[] = [
      '#theme' => 'feed_icon',
      '#url' => $url,
      '#title' => $title,
    ];

    // Attach a link to the RSS feed, which is an alternate representation.
    $build['#attached']['html_head_link'][][] = array(
      'rel' => 'alternate',
      'type' => 'application/rss+xml',
      'title' => $title,
      'href' => $url,
    );
  }
  protected function defineOptions() {
    $options = parent::defineOptions();
    $options['description'] = array(
      'default' => '',
    );
    return $options;
  }
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form, $form_state);
    $form['description'] = array(
      '#type' => 'textfield',
      '#title' => $this
        ->t('RSS description'),
      '#default_value' => $this->options['description'],
      '#description' => $this
        ->t('This will appear in the RSS feed itself.'),
      '#maxlength' => 1024,
    );
  }

  /**
   * Return an array of additional XHTML elements to add to the channel.
   *
   * @return
   *   A render array.
   */
  protected function getChannelElements() {
    return array();
  }

  /**
   * Get RSS feed description.
   *
   * @return string
   *   The string containing the description with the tokens replaced.
   */
  public function getDescription() {
    $description = $this->options['description'];

    // Allow substitutions from the first row.
    $description = $this
      ->tokenizeValue($description, 0);
    return $description;
  }
  public function render() {
    if (empty($this->view->rowPlugin)) {
      debug('Drupal\\views\\Plugin\\views\\style\\Rss: Missing row plugin');
      return array();
    }
    $rows = [];

    // This will be filled in by the row plugin and is used later on in the
    // theming output.
    $this->namespaces = array(
      'xmlns:dc' => 'http://purl.org/dc/elements/1.1/',
    );

    // Fetch any additional elements for the channel and merge in their
    // namespaces.
    $this->channel_elements = $this
      ->getChannelElements();
    foreach ($this->channel_elements as $element) {
      if (isset($element['namespace'])) {
        $this->namespaces = array_merge($this->namespaces, $element['namespace']);
      }
    }
    foreach ($this->view->result as $row_index => $row) {
      $this->view->row_index = $row_index;
      $rows[] = $this->view->rowPlugin
        ->render($row);
    }
    $build = array(
      '#theme' => $this
        ->themeFunctions(),
      '#view' => $this->view,
      '#options' => $this->options,
      '#rows' => $rows,
    );
    unset($this->view->row_index);
    return $build;
  }

}

Classes

Namesort descending Description
Rss Default style plugin to render an RSS feed.