Update the settings of a View Display programmatically I can load a ViewExecutable and create a new Display programmatically:

$view = Views::getView('existing_view');
$display = $view-&gt;newDisplay('page', 'New page', 'page_2');


But how can I update the settings for the new display programmatically?

The display is an instance of \Drupal\views\Plugin\views\display\Page but I can't see any way of saving options to it.

The setOption method exists, but how can persist the options to storage?
Answering my own question:
The settings are not made on the display, but on the handler.

$view = Views::getView('existing_view');
$display = $view-&gt;newDisplay('page', 'New page', 'page_2');

// ViewExecutable::setHandlerOption($display_id, $type, $id, $option, $value)
$view-&gt;setHandlerOption('page_2', 'argument', 'nid', 'admin_label', 'Foo');
$view-&gt;save();


Options and values correspond to the values in a View YAML config file, under display_options.

Important is that you find out the correct $type argument.

I had a look at the array keys returned from ViewExecutable::getHandlers.


"field"
"argument"
"sort"
"filter"
"relationship"
"header"
"footer"
"empty"