0

I've a simple problem. In Views I've city filter(exposed) set that'll show jobs in a city. Now I've set the same City in contextual filters as well with the condition to show all values when no argument is supplied. So this view is "General Advanced Job Search"

Now I want to offer "Jobs in Citi1", "Jobs in Citi2". But I want to reuse the same View without duplicating it. I'd call it "Advanced Job Search given a city".

So I can pass the arguments as Citi1 etc and it'd show Jobs in Citi1 at the same time it'll show City filter as drop down in Filter Criteria. I want to hide this City in Filter criteria as it is of no use as cities are already being limited by the argument passed(Citi1).

I've tried searching here and there but nothing found.

In short if argument is passed to a view I want to hide an exposed field show in filter criteria.

2

The following code will help you to solve your issue.

/**
 * Implement hook_form_alter().
 */
function mymodule_form_alter(&$form, &$form_state, $form_id) {

  if($form_id == 'views_exposed_form') {
    if($form['#id'] == 'views-exposed-form-myview-page') {
       // argument 1 represent city1 
      if(arg(1)) {
        // hide city field 
        unset($form['#info']['filter-jobs_in_city']);
        hide($form['jobs_in_city']);
      }
    }
  }
}

Notes:

  • Replace form id views-exposed-form-myview-page with your own form id
  • Replace argument 1 with the right City1 argument index
  • Replace jobs_in_city field name with your own city field
0

You can use this module

https://www.drupal.org/project/filter_harmonizer

It fixed that problem for me. if you have the same exposed filter as a contextual filter this module helps you to avoid this problem. Read the instrucions in the module's page

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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