TransWikia.com

Limit filter operators

Drupal Answers Asked on November 5, 2021

Is there a way to limit the operators for views-filtering for users. I want them to only have “starts-with”, “contains” and “same”. But not the rest. Do I have to form_alter with a custom module? Or is there some intern way to achieve that?

One Answer

I don't think there is an option to sort the exposed operators.

You can do it with a custom module using hook_form_alter().

Example:

function module_name_form_alter(&$form, &$form_state, $form_id) {

  if ($form_id == 'views_exposed_form' && $form_state['view']->name == 'view_name') {
    unset($form['field_name_filter_op']['#options']['empty']);
    unset($form['field_name_filter_op']['#options']['not empty']);
  }

}

You can find the form details using "dpm()" from devel module.

  • dpm($form_id);
  • dpm($form);
  • dpm($form_state);

Answered by NeoHQ on November 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP