Seems like the exposed_form_plugin in views_exposed_form(&$form_state) is null:

$exposed_form_plugin = $form_state['exposed_form_plugin'];

How can this happen? I use a view which was created with Views 2 and a custom menu callback which embeds the view including exposed filters.

Any idea?

CommentFileSizeAuthor
#2 nre-view.txt10.78 KBgnindl

Comments

dawehner’s picture

Status: Active » Postponed (maintainer needs more info)

How do you embed the view?

Perhaps it would be also cool if you export your view so it's reproducable

gnindl’s picture

Status: Postponed (maintainer needs more info) » Active
StatusFileSize
new10.78 KB

Ok, the process is like this:

1. A JSON request is processed via JavaScript, i. e. $.getJSON(settings['dialog'], function(data, textStatus) ...
2. Then a custom menu call back is accessed
3. The view is rendered like
3.a $output = call_user_func_array('views_embed_view', $args); or
3.b $output = views_embed_view($view->name, $display_id);
4. The $output is returned as a JSON string:
$ret_msg['data'] = $output; drupal_json($ret_msg);
5. Finally on the client side the rendered html (data) is inserted in the DOM and processed further with jQuery UI

That's about it. For more details please have a look at this release especially at the files
- js/explorer.actions.js from line 38 - 56
- includes/nodereference_explorer.menu.inc, function nodereference_explorer_dialog()
- includes/nodereference_explorer.views.class.inc, function get_display()

Probably the View is generating this problem (see attachment). Nevertheless I am looking for a View which is compatible with the versions 2 & 3.

gnindl’s picture

Title: Call to a member function exposed_form_alter() on a non-object in .../views/views.module on line 1054 » How to render exposed filters in Views 3 programmatically?

I detected the source of the problem. It's the way how exposed forms are included programmatically. Here's a working code from Views 2:

   $view = $this->view->clone_view();
    $view->set_display($display_id);
    $view->init_handlers(); //initialize display handlers
    $form_state = array(
      'view' => $view,
      'display' => $view->display_handler->display,
      'method' => 'get',
      'rerender' => TRUE,
      'no_redirect' => TRUE,
    );
    $form = drupal_build_form('views_exposed_form', $form_state); //create the filter form
    return $form;

However Views 3 requires a form plugin object in the $form_state array, i. e. $form_state['exposed_form_plugin'];

So my question is: Is the client responsible for creating this object or is rendering of forms done in a different way?

For my purposes it would be convenient to keep this code, as I don't see any advantage of creating a plugin object manually.

merlinofchaos’s picture

No, it should use the plugin that's been assigned in the View, so you should not need to create a plugin unless you need to provide some functionality.

gnindl’s picture

Status: Active » Fixed

Thanks merlinofchaos, the solution is quite easy now. I just have to get the exposed form plugin from the view object. This code works for me in Views 2 & 3:

//create a view object first, e. g. $view = views_get_view('myViewName');
//then set the demanded display_id, e. g. $display_id = 'page_1';
$view->set_display($display_id);
$view->init_handlers(); //initialize display handlers
$form_state = array(
  'view' => $view,
  'display' => $view->display_handler->display,
  'exposed_form_plugin' => $view->display_handler->get_plugin('exposed_form'), //exposed form plugins are used in Views 3
  'method' => 'get',
  'rerender' => TRUE,
  'no_redirect' => TRUE,
);
$form = drupal_build_form('views_exposed_form', $form_state); //create the filter form
//you now have a form array which can be themed or further altered...

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

alanpeart’s picture

It took me a long, long time to track down this information - thank you!

mathieu’s picture

Just adding a quick note here, for people stumbling on this issue. If all you want is to have the filters displayed in a block, you can use the "Exposed form in block" option that you'll find in your views display settings.

Anonymous’s picture

I'm trying to use this code to embed an exposed filter from a view with a dynamic URL.

Basically I have 'directories' of nodes that get sorted by 'city'.

The view works great using the city/%/directory url.

However, I want to embed the exposed filter on the panel page '/city/orlando' (for example) and have the view take the city from the URL and use the same on in it's own URL. (/city/orlando/directory?my_filter=search)

Right now, it either applies the argument to the panel URL or '/city/all/directory'.

Any help would be appreciated!

Thanks,

EDIT: Sorry, I'm using 7.8 and the Views 3.
Drew