remove a logic operator(unlocked) of a exposed fil

2019-05-30 16:44发布

I have a view where I am exposing a filter which is the Price of a product. I want the user to be able to choose the price(filter based on price), So I exposed the filter, then unlocked the operator and all of them are unlocked(operators). Is there a way where I can unlock only a few operators such as "Is less than", "In Between", "Is Greater than". I don't want the user to be selecting "Is Empty", "Is not empty".

1条回答
仙女界的扛把子
2楼-- · 2019-05-30 17:35

This is pretty easy with a custom module and hook_form_alter():

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

  // Change test to the name of your view
  if ($form_id == 'views_exposed_form' && $form_state['view']->name == 'test') {

    // Change field_test_value_op to the identifier you specified
    unset($form['field_test_value_op']['#options']['empty']);
    unset($form['field_test_value_op']['#options']['not empty']);
  }
}
查看更多
登录 后发表回答