1

I have a view with an exposed filter using the hierarchical select module for taxonomy.

/browse?category=12345

On the same view, I have an argument which does the same thing.

/browse/12345

I want my users to navigate using only the select filter, but this doesn't support breadcrumbs and page titles like the argument does. I wrote a bit of code to inject the filter value into the argument, and that works fine, but the next time I change a filter and refresh the view, the URL changes to that previous value while showing the new value.

/browse/(term id of last selection)?category=(term id of new selection) aka /browse/111?category=333

How can I discard this url change and keep things how they work the first time?

function MODULE_views_pre_view(&$view, &$display_id, &$args) {
  switch ($view->name) {
    case 'resources':
      if ($display_id == 'page_1') {
        if ($_GET['category']) {
          $args = array($_GET['category']);
        }
      }
    break;
  }
}
  • Maybe it is a caching issue, disable temporally the caching for views, and see what happen? t disable the caching for views visit this page "/admin/structure/views/settings/advanced" – Mouad Mar 7 '14 at 21:16
0

The exposed filter form is always going to add a query string to the current URL as it's a simple GET form.

You need a form with a submit handler that redirects to the argument based path. You could do this to the existing exposed filter with hook_form_FORM_ID_alter or create a custom form and expose it in a block.

To make the existing form redirect you'd need to do something like:

function mytheme_form_views_exposed_form_alter(&$form, &$form_state) {
  $form['#method'] = 'POST';
  $form['#submit'] = array('mytheme_redirect_taxonomy');
}

function mytheme_redirect_taxonomy($form, &$form_state) {
  $form_state['redirect'] = '/browse/' . $form_state['values']['category'];
}
  • I understand what your saying. My taxonomy select requires the use of the query string value, unless I were to somehow get that to look at the argument as well. – Ryan Hartman Mar 8 '14 at 5:41
  • I think I need to implement your code sample so that the exposed form posts to the view argument. Then when the filter loads also pass that the value from the argument too. This way I would eliminate the query string requirement completely. – Ryan Hartman Mar 8 '14 at 5:48
  • I cannot get this to work. $form_state['redirect'] in a submit handler does not redirect my form, at all. I was wondering if it was the hierarchical select so I created a new view with an exposed node_type filter and still nothing. – Ryan Hartman Mar 14 '14 at 3:04

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.