1

I have a view page like http://localhost/drupal/myviews, which looks like in the following screenshot:

screenshot

I pass arguments to this page using a URL like http://localhost/drupal/myviews/voc3; the page looks like in the following screenshot:

screenshot

So all this works fine. When the argument is passed within the URL, can I highlight that argument in the exposed filter?

2

I was able to create a solution for a regular Taxonomy: Term ID (no depth) filter, so this may not be applicable for you (the filter with depth was behaving erratically for me).

This code will set the dropdown element to the term provided in the argument, and will defer to the dropdown selection if one is chosen.

Add this to your custom module and then flush caches:

function mymodule_form_views_exposed_form_alter(&$form, &$form_state) {
  if($form_state['view']->name == 'name_of_view') {
    if(!isset($_GET['tid'])) {
      $arg = arg(1);
      if(isset($arg)) {
        $selected_value = array_search($arg, $form['tid']['#options']);
        if(isset($selected_value)) {
          $form_state['input']['tid'] = $selected_value;
        }
      }
    }
    else {
      $form_state['view']->args = array();
    }
  }
}

You can try changing every instance of 'tid' to 'term_node_tid_depth' if you are going with a Taxonomy With Depth filter (use a dpm($form) to verify the filter name).

| improve this answer | |

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.