0

I'm trying to edit the variables that go from Views into the form array editted by hook_form_alter() and the tpl file views-exposed-form.tpl.php. Specifically, I'm trying to use the contents of $view->exposed_input for form theming, without resorting to using $view = views_get_current_view();

I've tried working my way up the order of execution defined here:

  • hook_views_pre_view
  • hook_views_pre_build
  • hook_views_post_build
  • hook_views_pre_execute
  • hook_views_post_execute
  • hook_views_pre_render
  • hook_views_post_render

...but I'm stuck. At hook_views_pre_render(), $view->exposed_widgets gives me already-rendered HTML, so it's clearly too late, but the earlier ones don't give me anything at all.

Based on How to choose between all the views hooks?, I've tried using a preprocess hook based on the tpl file name, like hook_preprocess_views_exposed_form(), but the view isn't in scope here, I'm looking for the last views hook before this where I can find data from the view to these variables.

What I want to do, is take the contents of $view->exposed_input, and pass it through to the exposed form tpl file so that I can add a facet-like summary of current filters to my view. Which is the Views hook where I can do this?

I'm using Better Exposed Filters module, so if there are any hooks or tricks specific to that,they'd be welcome.

1

You can do what you need by adding a custom property to your form array via form alter:

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

  // get the related view
  $view = $form_state['view'];

  // get the exposed_input and store it into a custom property
  $form['#exposed_input'] = $view->exposed_input; 

}

The form array is directly available as a variable in your views-exposed-form.tpl.php, try adding the following to the end of that tpl file:

<pre><?php print_r($form['#exposed_input']); ?></pre>

Hope this helps!

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.