Views Exposed Filters and Drupal Get Form

Last modified
Sunday, February 5, 2017 - 21:21

This is a PHP function I wrote that helps simulating a drupal get form for Views Exposed Filters, it returns the exposed form array so you can theme it or alter it:

function _get_exposed_form($view, $display_id){
  $view = views_get_view($view);
  $view->set_display($display_id);
  $view->init_handlers();
  $form_state = array(
    'view' => $view,
    'display' => $view->display_handler->display, 
    'exposed_form_plugin' => $view->display_handler->get_plugin('exposed_form'),
    'method' => 'get',
     'rerender' => TRUE,
     'no_redirect' => TRUE,
   );
   $form = drupal_build_form('views_exposed_form', $form_state);
   $form_redered = drupal_render($form);
	
   return $form_rendered;
}

I took this idea from the views/plugins/views_plugin_exposed_form.inc::render_exposed_form method.

Hope it helps!

Add new comment

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.