function WizardPluginBase::addDisplays

Same name and namespace in other branches
  1. 9 core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php \Drupal\views\Plugin\views\wizard\WizardPluginBase::addDisplays()
  2. 8.9.x core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php \Drupal\views\Plugin\views\wizard\WizardPluginBase::addDisplays()
  3. 11.x core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php \Drupal\views\Plugin\views\wizard\WizardPluginBase::addDisplays()

Adds the array of display options to the view, with appropriate overrides.

1 call to WizardPluginBase::addDisplays()
WizardPluginBase::instantiateView in core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php
Instantiates a view object from form values.

File

core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php, line 766

Class

WizardPluginBase
Base class for Views wizard plugins.

Namespace

Drupal\views\Plugin\views\wizard

Code

protected function addDisplays(View $view, $display_options, $form, FormStateInterface $form_state) {
  // Initialize and store the view executable to get the display plugin
  // instances.
  $executable = $view->getExecutable();
  // Display: Default
  $default_display = $executable->newDisplay('default', 'Default', 'default');
  foreach ($display_options['default'] as $option => $value) {
    $default_display->setOption($option, $value);
  }
  // Display: Page
  if (isset($display_options['page'])) {
    $display = $executable->newDisplay('page', 'Page', 'page_1');
    // The page display is usually the main one (from the user's point of
    // view). Its options should therefore become the overall view defaults,
    // so that new displays which are added later automatically inherit them.
    $this->setDefaultOptions($display_options['page'], $display, $default_display);
    // Display: Feed (attached to the page).
    if (isset($display_options['feed'])) {
      $display = $executable->newDisplay('feed', 'Feed', 'feed_1');
      $this->setOverrideOptions($display_options['feed'], $display, $default_display);
    }
  }
  // Display: Block.
  if (isset($display_options['block'])) {
    $display = $executable->newDisplay('block', 'Block', 'block_1');
    // When there is no page, the block display options should become the
    // overall view defaults.
    if (!isset($display_options['page'])) {
      $this->setDefaultOptions($display_options['block'], $display, $default_display);
    }
    else {
      $this->setOverrideOptions($display_options['block'], $display, $default_display);
    }
  }
  // Display: REST export.
  if (isset($display_options['rest_export'])) {
    $display = $executable->newDisplay('rest_export', 'REST export', 'rest_export_1');
    // If there is no page or block, the REST export display options should
    // become the overall view defaults.
    if (!isset($display_options['page']) && !isset($display_options['block'])) {
      $this->setDefaultOptions($display_options['rest_export'], $display, $default_display);
    }
    else {
      $this->setOverrideOptions($display_options['rest_export'], $display, $default_display);
    }
  }
  // Initialize displays and merge all plugin default values.
  $executable->mergeDefaults();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.