function WizardPluginBase::setDefaultOptions

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

Sets options for a display and makes them the default options if possible.

This function can be used to set options for a display when it is desired that the options also become the defaults for the view whenever possible. This should be done for the "primary" display created in the view wizard, so that new displays which the user adds later will be similar to this one.

Parameters

array $options: An array whose keys are the name of each option and whose values are the desired values to set.

\Drupal\views\Plugin\views\display\DisplayPluginBase $display: The display handler which the options will be applied to. The default display will actually be assigned the options (and this display will inherit them) when possible.

\Drupal\views\Plugin\views\display\DisplayPluginBase $default_display: The default display handler, which will store the options when possible.

1 call to WizardPluginBase::setDefaultOptions()
WizardPluginBase::addDisplays in core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php
Adds the array of display options to the view, with appropriate overrides.

File

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

Class

WizardPluginBase
Base class for Views wizard plugins.

Namespace

Drupal\views\Plugin\views\wizard

Code

protected function setDefaultOptions($options, DisplayPluginBase $display, DisplayPluginBase $default_display) {
    foreach ($options as $option => $value) {
        // If the default display supports this option, set the value there.
        // Otherwise, set it on the provided display.
        $default_value = $default_display->getOption($option);
        if (isset($default_value)) {
            $default_display->setOption($option, $value);
        }
        else {
            $display->setOption($option, $value);
        }
    }
}

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