I'm creating a views filter, and I would like to limit it by display type. How do I do that?

I'm creating a custom filter for the entity_browser view display (entity_browser/src/Plugin/views/display/EntityBrowser.php).

Since it's only relevant for this display, I would like it only appear in the list of filters when on that display. How do I do that?

1 Answer 1


This works, you can use a form alter hook to check the display plugin, and then remove options from the AddHandler form.

 * Implements hook_form_FORM_ID_alter().
function entity_browser_form_views_ui_add_handler_form_alter(&$form, FormStateInterface $form_state) {

  // Hide 'entity_browser_bundle' filter plugin for displays other than
  // entity_browser.
  $display_id = $form_state->get('display_id');
  $display_plugin = $form_state

  if ($display_plugin != 'entity_browser') {
    foreach ($form['options']['name']['#options'] as $key => $value) {
      if (strpos($key, 'entity_browser_bundle') !== FALSE) {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.