class Feed

The plugin that handles a feed, such as RSS or atom.

Plugin annotation


@Plugin(
  id = "feed",
  title = @Translation("Feed"),
  help = @Translation("Display the view as a feed, such as an RSS feed."),
  uses_hook_menu = TRUE,
  admin = @Translation("Feed")
)

Hierarchy

Expanded class hierarchy of Feed

Related topics

1 file declares its use of Feed
ViewStorageTest.php in drupal/core/modules/views/lib/Drupal/views/Tests/ViewStorageTest.php
Definition of Drupal\views\Tests\ViewStorageTest.
5 string references to 'Feed'
views.view.frontpage.yml in drupal/core/modules/views/config/views.view.frontpage.yml
drupal/core/modules/views/config/views.view.frontpage.yml
views.view.taxonomy_term.yml in drupal/core/modules/views/config/views.view.taxonomy_term.yml
drupal/core/modules/views/config/views.view.taxonomy_term.yml
views.view.test_feed_display.yml in drupal/core/modules/views/tests/views_test_config/test_views/views.view.test_feed_display.yml
drupal/core/modules/views/tests/views_test_config/test_views/views.view.test_feed_display.yml
ViewStorageTest::displayMethodTests in drupal/core/modules/views/lib/Drupal/views/Tests/ViewStorageTest.php
Tests the display related functions like getDisplaysList().
WizardPluginBase::addDisplays in drupal/core/modules/views/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php
Adds the array of display options to the view, with appropriate overrides.

File

drupal/core/modules/views/lib/Drupal/views/Plugin/views/display/Feed.php, line 29
Contains Drupal\views\Plugin\views\display\Feed.

Namespace

Drupal\views\Plugin\views\display
View source
class Feed extends PathPluginBase {

  /**
   * Whether the display allows the use of AJAX or not.
   *
   * @var bool
   */
  protected $usesAJAX = FALSE;

  /**
   * Whether the display allows the use of a pager or not.
   *
   * @var bool
   */
  protected $usesPager = FALSE;
  public function init(ViewExecutable $view, &$display, $options = NULL) {
    parent::init($view, $display, $options);

    // Set the default row style. Ideally this would be part of the option
    // definition, but in this case it's dependent on the view's base table,
    // which we don't know until init().
    $row_plugins = views_fetch_plugin_names('row', $this
      ->getStyleType(), array(
      $view->storage
        ->get('base_table'),
    ));
    $default_row_plugin = key($row_plugins);
    if (empty($this->options['row']['type'])) {
      $this->options['row']['type'] = $default_row_plugin;
    }
  }

  /**
   * Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::getStyleType().
   */
  protected function getStyleType() {
    return 'feed';
  }

  /**
   * Overrides \Drupal\views\Plugin\views\display\PathPluginBase::execute().
   */
  public function execute() {
    parent::execute();
    $output = $this->view
      ->render();
    if (empty($output)) {
      throw new NotFoundHttpException();
    }
    $response = $this->view
      ->getResponse();
    $response
      ->setContent($output);
    return $response;
  }

  /**
   * Overrides \Drupal\views\Plugin\views\display\PathPluginBase::preview().
   */
  public function preview() {
    if (!empty($this->view->live_preview)) {
      return '<pre>' . check_plain($this->view
        ->render()) . '</pre>';
    }
    return $this->view
      ->render();
  }

  /**
   * Overrides \Drupal\views\Plugin\views\display\PathPluginBase::render().
   */
  public function render() {
    return $this->view->style_plugin
      ->render($this->view->result);
  }

  /**
   * Overrides \Drupal\views\Plugin\views\displays\DisplayPluginBase::defaultableSections().
   */
  public function defaultableSections($section = NULL) {
    $sections = parent::defaultableSections($section);
    if (in_array($section, array(
      'style',
      'row',
    ))) {
      return FALSE;
    }

    // Tell views our sitename_title option belongs in the title section.
    if ($section == 'title') {
      $sections[] = 'sitename_title';
    }
    elseif (!$section) {
      $sections['title'][] = 'sitename_title';
    }
    return $sections;
  }

  /**
   * Overrides \Drupal\views\Plugin\views\display\PathPluginBase::defineOptions().
   */
  protected function defineOptions() {
    $options = parent::defineOptions();
    $options['displays'] = array(
      'default' => array(),
    );

    // Overrides for standard stuff:
    $options['style']['contains']['type']['default'] = 'rss';
    $options['style']['contains']['options']['default'] = array(
      'description' => '',
    );
    $options['sitename_title']['default'] = FALSE;
    $options['row']['contains']['type']['default'] = '';
    $options['defaults']['default']['style'] = FALSE;
    $options['defaults']['default']['row'] = FALSE;
    return $options;
  }

  /**
   * Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::optionsSummary().
   */
  public function optionsSummary(&$categories, &$options) {
    parent::optionsSummary($categories, $options);

    // Since we're childing off the 'path' type, we'll still *call* our
    // category 'page' but let's override it so it says feed settings.
    $categories['page'] = array(
      'title' => t('Feed settings'),
      'column' => 'second',
      'build' => array(
        '#weight' => -10,
      ),
    );
    if ($this
      ->getOption('sitename_title')) {
      $options['title']['value'] = t('Using the site name');
    }
    $displays = array_filter($this
      ->getOption('displays'));
    if (count($displays) > 1) {
      $attach_to = t('Multiple displays');
    }
    elseif (count($displays) == 1) {
      $display = array_shift($displays);
      $displays = $this->view->storage
        ->get('display');
      if (!empty($displays[$display])) {
        $attach_to = check_plain($displays[$display]['display_title']);
      }
    }
    if (!isset($attach_to)) {
      $attach_to = t('None');
    }
    $options['displays'] = array(
      'category' => 'page',
      'title' => t('Attach to'),
      'value' => $attach_to,
    );
  }

  /**
   * Overrides \Drupal\views\Plugin\views\display\PathPluginBase::buildOptionsForm().
   */
  public function buildOptionsForm(&$form, &$form_state) {

    // It is very important to call the parent function here.
    parent::buildOptionsForm($form, $form_state);
    switch ($form_state['section']) {
      case 'title':
        $title = $form['title'];

        // A little juggling to move the 'title' field beyond our checkbox.
        unset($form['title']);
        $form['sitename_title'] = array(
          '#type' => 'checkbox',
          '#title' => t('Use the site name for the title'),
          '#default_value' => $this
            ->getOption('sitename_title'),
        );
        $form['title'] = $title;
        $form['title']['#states'] = array(
          'visible' => array(
            ':input[name="sitename_title"]' => array(
              'checked' => FALSE,
            ),
          ),
        );
        break;
      case 'displays':
        $form['#title'] .= t('Attach to');
        $displays = array();
        foreach ($this->view->storage
          ->get('display') as $display_id => $display) {

          // @todo The display plugin should have display_title and id as well.
          if (!empty($this->view->displayHandlers[$display_id]) && $this->view->displayHandlers[$display_id]
            ->acceptAttachments()) {
            $displays[$display_id] = $display['display_title'];
          }
        }
        $form['displays'] = array(
          '#type' => 'checkboxes',
          '#description' => t('The feed icon will be available only to the selected displays.'),
          '#options' => $displays,
          '#default_value' => $this
            ->getOption('displays'),
        );
        break;
      case 'path':
        $form['path']['#description'] = t('This view will be displayed by visiting this path on your site. It is recommended that the path be something like "path/%/%/feed" or "path/%/%/rss.xml", putting one % in the path for each contextual filter you have defined in the view.');
    }
  }

  /**
   * Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::submitOptionsForm().
   */
  public function submitOptionsForm(&$form, &$form_state) {
    parent::submitOptionsForm($form, $form_state);
    switch ($form_state['section']) {
      case 'title':
        $this
          ->setOption('sitename_title', $form_state['values']['sitename_title']);
        break;
      case 'displays':
        $this
          ->setOption($form_state['section'], $form_state['values'][$form_state['section']]);
        break;
    }
  }

  /**
   * Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::attachTo().
   */
  public function attachTo($display_id) {
    $displays = $this
      ->getOption('displays');
    if (empty($displays[$display_id])) {
      return;
    }

    // Defer to the feed style; it may put in meta information, and/or
    // attach a feed icon.
    $plugin = $this
      ->getPlugin('style');
    if ($plugin) {
      $clone = $this->view
        ->cloneView();
      $clone
        ->setDisplay($this->display['id']);
      $clone
        ->buildTitle();
      $plugin
        ->attach_to($display_id, $this
        ->getPath(), $clone
        ->getTitle());

      // Clean up
      $clone
        ->destroy();
      unset($clone);
    }
  }

  /**
   * Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::usesLinkDisplay().
   */
  public function usesLinkDisplay() {
    return TRUE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DisplayPluginBase::$extender property Stores all available display extenders.
DisplayPluginBase::$handlers property
DisplayPluginBase::$output public property Stores the rendered output of the display.
DisplayPluginBase::$plugins protected property An array of instantiated plugins used in this display.
DisplayPluginBase::$usesAreas protected property Whether the display allows area plugins. 1
DisplayPluginBase::$usesAttachments protected property Whether the display allows attachments. 4
DisplayPluginBase::$usesMore protected property Whether the display allows the use of a 'more' link or not.
DisplayPluginBase::$usesOptions protected property Overrides Drupal\views\Plugin\Plugin::$usesOptions. Overrides PluginBase::$usesOptions
DisplayPluginBase::$view property The top object of a view. Overrides PluginBase::$view
DisplayPluginBase::acceptAttachments public function Determines whether this display can use attachments.
DisplayPluginBase::access public function Determine if the user has access to this display of the view.
DisplayPluginBase::destroy public function Clears a plugin. Overrides PluginBase::destroy
DisplayPluginBase::displaysExposed public function Determine if this display should display the exposed filters widgets, so the view will know whether or not to render them. 1
DisplayPluginBase::formatThemes protected function Format a list of theme templates for output by the theme info helper.
DisplayPluginBase::getArgumentsTokens public function Returns to tokens for arguments.
DisplayPluginBase::getArgumentText public function Provide some helpful text for the arguments. The result should contain of an array with 1
DisplayPluginBase::getFieldLabels public function Retrieve a list of fields for the current display with the relationship associated if it exists.
DisplayPluginBase::getHandler public function Get the handler object for a single handler.
DisplayPluginBase::getHandlers public function Get a full array of handlers for $type. This caches them.
DisplayPluginBase::getLinkDisplay public function Check to see which display to use when creating links within a view using this display.
DisplayPluginBase::getOption public function Intelligently get an option either from this display or from the default display, if directed to do so.
DisplayPluginBase::getPagerText public function Provide some helpful text for pagers. 1
DisplayPluginBase::getPath public function Return the base path to use for this display.
DisplayPluginBase::getPlugin public function Get the instance of a plugin, for example style or row.
DisplayPluginBase::getSpecialBlocks public function Provide the block system with any exposed widget blocks for this display.
DisplayPluginBase::getUrl public function
DisplayPluginBase::hookBlockList public function If this display creates a block, implement one of these.
DisplayPluginBase::hookMenu public function If this display creates a page with a menu item, implement it here.
DisplayPluginBase::isAJAXEnabled public function Whether the display is actually using AJAX or not.
DisplayPluginBase::isDefaultDisplay public function Determine if this display is the 'default' display which contains fallback settings 1
DisplayPluginBase::isDefaulted public function Determine if a given option is set to use the default display or the current display
DisplayPluginBase::isEnabled public function Whether the display is enabled.
DisplayPluginBase::isIdentifierUnique public function Check if the provided identifier is unique.
DisplayPluginBase::isMoreEnabled public function Whether the display is using the 'more' link or not.
DisplayPluginBase::isPagerEnabled public function Whether the display is using a pager or not.
DisplayPluginBase::optionLink public function Because forms may be split up into sections, this provides an easy URL to exactly the right section. Don't override this.
DisplayPluginBase::optionsOverride public function If override/revert was clicked, perform the proper toggle.
DisplayPluginBase::overrideOption public function Set an option and force it to be an override.
DisplayPluginBase::preExecute public function Set up any variables on the view prior to execution. These are separated from execute because they are extremely common and unlikely to be overridden on an individual display.
DisplayPluginBase::query public function Inject anything into the query that the display handler needs. Overrides PluginBase::query
DisplayPluginBase::renderArea public function
DisplayPluginBase::renderEmpty public function
DisplayPluginBase::renderFilters public function Not all display plugins will support filtering
DisplayPluginBase::renderFooter public function Render the footer of the view.
DisplayPluginBase::renderHeader public function Render the header of the view.
DisplayPluginBase::renderMoreLink public function Render the 'more' link
DisplayPluginBase::renderPager public function Not all display plugins will suppert pager rendering. 1
DisplayPluginBase::setOption public function Intelligently set an option either from this display or from the default display, if directed to do so.
DisplayPluginBase::setOverride public function Flip the override setting for the given section.
DisplayPluginBase::useGroupBy public function Does the display have groupby enabled?
DisplayPluginBase::useMoreAlways public function Should the enabled display more link be shown when no more items?
DisplayPluginBase::useMoreText public function Does the display have custom link text?
DisplayPluginBase::usesAJAX public function Whether the display allows the use of AJAX or not. 1
DisplayPluginBase::usesAreas public function Returns whether the display can use areas. 1
DisplayPluginBase::usesAttachments public function Returns whether the display can use attachments. 4
DisplayPluginBase::usesBreadcrumb public function Check to see if the display needs a breadcrumb 1
DisplayPluginBase::usesExposed public function Determine if this display uses exposed filters, so the view will know whether or not to build them. 2
DisplayPluginBase::usesExposedFormInBlock public function Check to see if the display can put the exposed formin a block.
DisplayPluginBase::usesFields public function Determine if the display's style uses fields.
DisplayPluginBase::usesMore public function Whether the display allows the use of a 'more' link or not.
DisplayPluginBase::usesPager public function Whether the display allows the use of a pager or not. 2
DisplayPluginBase::validate public function Make sure the display and all associated handlers are valid. Overrides PluginBase::validate 1
DisplayPluginBase::viewSpecialBlocks public function Render any special blocks provided for this display.
Feed::$usesAJAX protected property Whether the display allows the use of AJAX or not. Overrides DisplayPluginBase::$usesAJAX
Feed::$usesPager protected property Whether the display allows the use of a pager or not. Overrides DisplayPluginBase::$usesPager
Feed::attachTo public function Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::attachTo(). Overrides DisplayPluginBase::attachTo
Feed::buildOptionsForm public function Overrides \Drupal\views\Plugin\views\display\PathPluginBase::buildOptionsForm(). Overrides PathPluginBase::buildOptionsForm
Feed::defaultableSections public function Overrides \Drupal\views\Plugin\views\displays\DisplayPluginBase::defaultableSections(). Overrides DisplayPluginBase::defaultableSections
Feed::defineOptions protected function Overrides \Drupal\views\Plugin\views\display\PathPluginBase::defineOptions(). Overrides PathPluginBase::defineOptions
Feed::execute public function Overrides \Drupal\views\Plugin\views\display\PathPluginBase::execute(). Overrides PathPluginBase::execute
Feed::getStyleType protected function Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::getStyleType(). Overrides DisplayPluginBase::getStyleType
Feed::init public function Overrides DisplayPluginBase::init
Feed::optionsSummary public function Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::optionsSummary(). Overrides PathPluginBase::optionsSummary
Feed::preview public function Overrides \Drupal\views\Plugin\views\display\PathPluginBase::preview(). Overrides DisplayPluginBase::preview
Feed::render public function Overrides \Drupal\views\Plugin\views\display\PathPluginBase::render(). Overrides DisplayPluginBase::render
Feed::submitOptionsForm public function Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::submitOptionsForm(). Overrides PathPluginBase::submitOptionsForm
Feed::usesLinkDisplay public function Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::usesLinkDisplay(). Overrides DisplayPluginBase::usesLinkDisplay
PathPluginBase::executeHookMenu public function Add this display's path information to Drupal's menu system.
PathPluginBase::hasPath public function Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::hasPath(). Overrides DisplayPluginBase::hasPath
PathPluginBase::validateOptionsForm public function Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::validateOptionsForm(). Overrides DisplayPluginBase::validateOptionsForm 1
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$definition public property Plugins's definition
PluginBase::$discovery protected property The discovery object.
PluginBase::$displayHandler public property The display object this plugin is for.
PluginBase::$options public property Options for this plugin will be held here.
PluginBase::$plugin_id protected property The plugin_id.
PluginBase::additionalThemeFunctions public function Provide a list of additional theme functions for the theme information page
PluginBase::getAvailableGlobalTokens public function Returns an array of available token replacements.
PluginBase::getDefinition public function Implements Drupal\Component\Plugin\PluginInterface::getDefinition(). Overrides PluginInspectionInterface::getDefinition
PluginBase::getPluginId public function Implements Drupal\Component\Plugin\PluginInterface::getPluginId(). Overrides PluginInspectionInterface::getPluginId
PluginBase::globalTokenForm public function Adds elements for available core tokens to a form.
PluginBase::globalTokenReplace public function Returns a string with any core tokens replaced.
PluginBase::pluginTitle public function Return the human readable name of the display.
PluginBase::setOptionDefaults protected function
PluginBase::summaryTitle public function Returns the summary of the settings in the display. 6
PluginBase::themeFunctions public function Provide a full list of possible theme templates used by this style. 1
PluginBase::unpackOptions public function Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away.
PluginBase::usesOptions public function Returns the usesOptions property. 8
PluginBase::__construct public function Constructs a Plugin object. Overrides PluginBase::__construct