Jungle Ran

Blog/Bloglet about Drupal, Ops, and mORe

Alter exposed views filters

Submitted by jungle on Thu, 12/24/2020 - 15:25
  1. /**
  2.  * Implements hook_form_FORM_ID_alter().
  3.  */
  4. function MODULE_NAME_form_views_exposed_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
  5. $view = $form_state->getStorage();
  6. $view_id = $view['view']->id();
  7. $display_id = $view['view']->current_display;
  8. if ($view_id === 'THE_VIEW_ID' && $display_id === 'THE_DISPLAY_ID_eg:page_1') {
  9. $form['foo'] = ['YOUR_FILTER'];
  10. }
  11. }
©2021 ranqiangjun.com. All rights reserved.