class entityreference_view_widget_plugin_exposed_form in Entity Reference View Widget 7
Extends the views plugin to make the exposed form work when included in an entityreference widget (itself included in an entity form). This is accomplished by using #ajax.
Hierarchy
- class \views_object
- class \views_plugin
Expanded class hierarchy of entityreference_view_widget_plugin_exposed_form
1 string reference to 'entityreference_view_widget_plugin_exposed_form'
- entityreference_view_widget_views_plugins in views/
entityreference_view_widget.views.inc - Implements hook_views_plugins().
File
- views/
entityreference_view_widget_plugin_exposed_form.inc, line 8
View source
class entityreference_view_widget_plugin_exposed_form extends views_plugin_exposed_form {
/**
* Overrides the parent render_exposed_form() method to just build the exposed
* form, but not render it.
* The output of this function will end up in $view->exposed_widgets, allowing
* it to be added to the widget.
* Unfortunately, the theme function will try to print $view->exposed_widgets,
* but the preprocess hook in the module will unset that in time.
*/
function render_exposed_form($block = FALSE) {
$form_state = array(
'view' => &$this->view,
'display' => &$this->display,
'method' => 'get',
'rerender' => TRUE,
'no_redirect' => TRUE,
'always_process' => TRUE,
'exposed_form_plugin' => $this,
);
// We must build and validate the form. One reason is that some filter
// handlers (like views_handler_filter_term_node_tid) store internal values
// at exposed_validate() - so, query results will be incorrect unless
// views_exposed_form_validate() is run.
$form = drupal_build_form('views_exposed_form', $form_state);
// Seed the defaults so that the view renders on first page load.
if (empty($this->view->exposed_data)) {
$this->view->exposed_data = $form_state['values'];
}
// Now get the actual form structure that the module needs.
$form = views_exposed_form($form, $form_state);
// Return only the needed parts of the form.
$return_form = array(
'#theme' => $form['#theme'],
'#info' => $form['#info'],
// Return a reference to the plugin, for validation / submission.
'#exposed_form_plugin' => $this,
);
foreach (element_get_visible_children($form) as $key) {
$return_form[$key] = $form[$key];
// Adjust the element's values to the exposed input used for filtering
// the view. Set #default_value since we do not return $form_state.
if (isset($form_state['input'][$key]) && isset($return_form[$key]['#default_value'])) {
$return_form[$key]['#default_value'] = $form_state['input'][$key];
}
}
return $return_form;
}
function exposed_form_alter(&$form, &$form_state) {
parent::exposed_form_alter($form, $form_state);
if (!empty($this->options['autosubmit'])) {
foreach (element_get_visible_children($form) as $key) {
// Other info will be filled-in by entityreference_view_widget_prepare_filters().
$form[$key]['#ajax'] = array(
'method' => 'replace',
'progress' => array(
'type' => 'throbber',
'message' => '',
),
);
}
}
else {
unset($form['submit']['#id']);
$form['submit']['#type'] = 'button';
$form['submit']['#ajax'] = array(
'method' => 'replace',
'progress' => array(
'type' => 'throbber',
'message' => '',
),
);
}
// The button basically doesn't work with JS on or off, without this.
$form['submit']['#name'] = 'apply';
// Don't run the default submit handlers, since all that is handled
// by the widget. (Do run validate handler; see above.)
$form['#submit'] = array();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
entityreference_view_widget_plugin_exposed_form:: |
function |
Overrides views_plugin_exposed_form:: |
||
entityreference_view_widget_plugin_exposed_form:: |
function |
Overrides the parent render_exposed_form() method to just build the exposed
form, but not render it.
The output of this function will end up in $view->exposed_widgets, allowing
it to be added to the widget.
Unfortunately, the theme function will… Overrides views_plugin_exposed_form:: |
||
views_object:: |
public | property | Handler's definition. | |
views_object:: |
public | property | Except for displays, options for the object will be held here. | 1 |
views_object:: |
function | Collect this handler's option definition and alter them, ready for use. | ||
views_object:: |
public | function | Views handlers use a special construct function. | 4 |
views_object:: |
public | function | Destructor. | 2 |
views_object:: |
public | function | 1 | |
views_object:: |
public | function | ||
views_object:: |
public | function | Always exports the option, regardless of the default value. | |
views_object:: |
public | function | Set default options on this object. | 1 |
views_object:: |
public | function | Set default options. | |
views_object:: |
public | function | Let the handler know what its full definition is. | |
views_object:: |
public | function | Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away. | |
views_object:: |
public | function | Unpack a single option definition. | |
views_object:: |
public | function | Unpacks each handler to store translatable texts. | |
views_object:: |
public | function | ||
views_plugin:: |
public | property | The current used views display. | |
views_plugin:: |
public | property | The plugin name of this plugin, for example table or full. | |
views_plugin:: |
public | property | The plugin type of this plugin, for example style or query. | |
views_plugin:: |
public | property |
The top object of a view. Overrides views_object:: |
1 |
views_plugin:: |
public | function | Provide a list of additional theme functions for the theme info page. | |
views_plugin:: |
public | function | Handle any special handling on the validate form. | 9 |
views_plugin:: |
public | function | Validate the options form. | 10 |
views_plugin:: |
public | function | Return the human readable name of the display. | |
views_plugin:: |
public | function | Returns the summary of the settings in the display. | 8 |
views_plugin:: |
public | function | Provide a full list of possible theme templates used by this style. | |
views_plugin:: |
public | function | Validate that the plugin is correct and can be saved. | 3 |
views_plugin_exposed_form:: |
public | function | This function is executed when exposed form is submited. | |
views_plugin_exposed_form:: |
public | function | ||
views_plugin_exposed_form:: |
public | function | Initialize the plugin. | |
views_plugin_exposed_form:: |
public | function |
Provide a form to edit options for this plugin. Overrides views_plugin:: |
1 |
views_plugin_exposed_form:: |
public | function |
Information about options for all kinds of purposes will be held here. Overrides views_object:: |
1 |
views_plugin_exposed_form:: |
public | function | ||
views_plugin_exposed_form:: |
public | function | ||
views_plugin_exposed_form:: |
public | function | ||
views_plugin_exposed_form:: |
public | function | 1 | |
views_plugin_exposed_form:: |
public | function |
Add anything to the query that we might need to. Overrides views_plugin:: |
1 |
views_plugin_exposed_form:: |
public | function |