You are here

public function DisplayPluginBase::setOverride in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/src/Plugin/views/display/DisplayPluginBase.php \Drupal\views\Plugin\views\display\DisplayPluginBase::setOverride()

Flip the override setting for the given section.

Parameters

string $section: Which option should be marked as overridden, for example "filters".

bool $new_state: Select the new state of the option:

  • TRUE: Revert new state option to default.
  • FALSE: Mark it as overridden.

Overrides DisplayPluginInterface::setOverride

2 calls to DisplayPluginBase::setOverride()
DisplayPluginBase::optionsOverride in core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
If override/revert was clicked, perform the proper toggle.
DisplayPluginBase::overrideOption in core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
Set an option and force it to be an override.

File

core/modules/views/src/Plugin/views/display/DisplayPluginBase.php, line 2053

Class

DisplayPluginBase
Base class for views display plugins.

Namespace

Drupal\views\Plugin\views\display

Code

public function setOverride($section, $new_state = NULL) {
  $options = $this
    ->defaultableSections($section);
  if (!$options) {
    return;
  }
  if (!isset($new_state)) {
    $new_state = empty($this->options['defaults'][$section]);
  }

  // For each option that is part of this group, fix our settings.
  foreach ($options as $option) {
    if ($new_state) {

      // Revert to defaults.
      unset($this->options[$option]);
      unset($this->display['display_options'][$option]);
    }
    else {

      // Copy existing values into our display.
      $this->options[$option] = $this
        ->getOption($option);
      $this->display['display_options'][$option] = $this->options[$option];
    }
    $this->options['defaults'][$option] = $new_state;
    $this->display['display_options']['defaults'][$option] = $new_state;
  }
}