Programmatically change the available options in a views exposed filter I have an existing view in which I want to change the available options in a view exposed filter. I can't manipulate the form because the modifications are dependant on other views data, so I thought I could use a view hook:

function my_mdoule_views_pre_view($view, $display_id, $args) {
  // This doesn't work unfortunately
  if ($display_id === 'gallery_media_select_modal') {

    $filters = $view-&gt;display_handler-&gt;getOption('filters');

    $filters['bundle']['operator'] = 'IN';
    $filters['bundle']['value'] = ['image' =&gt; 'image'];

    $view-&gt;display_handler-&gt;overrideOption('filters', $filters);
  }

}


This setting is basically the same that you can do in the UI, but like I said I need to do it dynamically.

I can see that this is in fact set correctly (and still set in later view hooks) but it's never picked up by the code that is responsible for building the exposed select.

I've found many similar questions, but conclusively they've only been answered for Drupal 7, e.g. https://groups.drupal.org/node/82219
I think you are very nearly on the right track, and I don't think you necessarily need a hook. I was able to perform essentially the same task with the following code in a class method.

// Get reference to your view.
$storage = \Drupal::entityTypeManager()-&gt;getStorage('view');
$view = $storage-&gt;load($view_id);

// Be sure to get a specific display.
$view-&gt;getExecutable()-&gt;setDisplay($display_id);
$display = $view-&gt;getExecutable()-&gt;getDisplay();

// Retrieve filters. If the combine fields filter is present,
// edit it then assign back using `overrideOption`.
$options = $display-&gt;getOption('filters');
if (isset($options['combine'])) {
  $options['combine']['fields'][$field_name] = $field_name;
  $display-&gt;overrideOption('filters', $options);
}

// This is the critical missing step.
$view-&gt;save();


I hope this helps.