0

Sorry if this is a known bug but I searched and couldn't find a related issue.

I have a view which has a "Feed" display (xml), and a "Views Pane" display.

On the "Feed" display the supplied path/URL for the display is "feed/xml".

The "Views Pane" display has a contextual filter for "Taxonomy term" and also a pager that has "Expose the Items Per Page" set to on.

Now when the "Views Pane" is included in a Panel, the Contextual Filter value (term id) is supplied from the Panel context (Node being viewed: term field on node). So now when you view the panel page and try to change the Items Per Page exposed form, it tries to submit the form to the "Feed" display's path which is "feed/xml" and that's wrong. Ideally the #action of the exposed form should be submitting to the current URL.

So I went back to the view and edited the "Views Pane" display, opened to "Allowed settings" and set "Path override" to on. And then went to the Panel config, and I put %node:url as the "Path override".

All well and good so far, but now when I view the Panel page and look at the exposed form's #action its the correct url BUT with added extra parameter which is the Contextual Filter's taxonomy term id. For example: if my current page is path/to/my/page then the #action of the form is path/to/my/page/115 where 115 is the ID of the taxonomy term currently supplied to the views pane through the panel context. So submitting the form produces a 404 in this case.

What I've tried so far is: - Preprocessing the panel pane (theme_preproces_panel_pane) which didn't help a great deal as the view was already rendered as HTML in the content key of the $variables array. At this point I realized preprocessing theme functions won't work. - So I moved on to Views hooks and tried hook_views_pre_render. dpm-ing the $view from this hook, I can see that $view->override_path (string) is the correct URL (without the extra term id), but the exposed form was also already rendered here in $view->exposed_widgets (string, rendered HTML) with the wrong URL (with extra term id).

So before I go through all Views hooks, and maybe not even come up with a solution, I wanted to ask this question, if anyone knows when exactly this exposed form is being rendered OR how I can stop the Taxonomy Term ID from being attached to %node:url token (Perhaps a simple configuration that I've missed or.. ?).

Edit

So I went through all the Views hooks. Also implemented a hook_form_views_exposed_form_alter. From the order the dpm's are being outputted, it looks like the order of execution is:

  • hook_views_pre_build
  • Exposed form gets built (dpm of hook_form_views_exposed_form_alter)
  • hook_views_post_build
  • hook_views_pre_execute
  • hook_views_post_execute

In hook_views_pre_build the path_override is correct. Form is not rendered yet.

In hook_views_exposed_form_alter the form render array is built, and $form['#action'] shows the wrong path with the extra term id.

So I need to somehow get in between these 2 functions and supply the correct #action...

  • I don't have an immediate answer, I'm not 100% sure why the argument is added to the URL, though I know I've done the same thing at some point and worked it out. A simple way to workaround it might be to have the page take an optional argument in the form is the term id. Not sure about it though, so commenting instead of answering. – Letharion Jan 24 '14 at 15:07
  • 1
    If you have the incorrect #action in the form alter, why don't you just correct it there? – Letharion Jan 24 '14 at 15:08
  • Oh of course... KISS ... view is available in $form_state['view'] ... didn't know that... – Beebee Jan 24 '14 at 15:12
1

Although this doesn't answer why exactly the term id is being attached (hoping someone might shed light on that), the simple solution thanks to @Letharion was to use the hook_form_views_exposed_form_alter:

function hook_form_views_exposed_form_alter(&$form, &$form_state) {
  $view = $form_state['view'];

  if($view->name == 'exhibitions' && $view->current_display == 'panel_pane_3') {
    $form['#action'] = $view->override_path;
  }
}

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.