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.
array $options: An array whose keys are the name of each option and whose values are the desired values to set.
Drupal\views\View\plugin\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\View\plugin\display\DisplayPluginBase $default_display: The default display handler, which will store the options when possible.
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);
}
}
}