You are here

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

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

Namesort descending Modifiers Type Description Overrides
entityreference_view_widget_plugin_exposed_form::exposed_form_alter function Overrides views_plugin_exposed_form::exposed_form_alter
entityreference_view_widget_plugin_exposed_form::render_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::render_exposed_form
views_object::$definition public property Handler's definition.
views_object::$options public property Except for displays, options for the object will be held here. 1
views_object::altered_option_definition function Collect this handler's option definition and alter them, ready for use.
views_object::construct public function Views handlers use a special construct function. 4
views_object::destroy public function Destructor. 2
views_object::export_option public function 1
views_object::export_options public function
views_object::export_option_always public function Always exports the option, regardless of the default value.
views_object::options Deprecated public function Set default options on this object. 1
views_object::set_default_options public function Set default options.
views_object::set_definition public function Let the handler know what its full definition is.
views_object::unpack_options public function Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away.
views_object::unpack_translatable public function Unpack a single option definition.
views_object::unpack_translatables public function Unpacks each handler to store translatable texts.
views_object::_set_option_defaults public function
views_plugin::$display public property The current used views display.
views_plugin::$plugin_name public property The plugin name of this plugin, for example table or full.
views_plugin::$plugin_type public property The plugin type of this plugin, for example style or query.
views_plugin::$view public property The top object of a view. Overrides views_object::$view 1
views_plugin::additional_theme_functions public function Provide a list of additional theme functions for the theme info page.
views_plugin::options_submit public function Handle any special handling on the validate form. 9
views_plugin::options_validate public function Validate the options form. 10
views_plugin::plugin_title public function Return the human readable name of the display.
views_plugin::summary_title public function Returns the summary of the settings in the display. 8
views_plugin::theme_functions public function Provide a full list of possible theme templates used by this style.
views_plugin::validate public function Validate that the plugin is correct and can be saved. 3
views_plugin_exposed_form::exposed_form_submit public function This function is executed when exposed form is submited.
views_plugin_exposed_form::exposed_form_validate public function
views_plugin_exposed_form::init public function Initialize the plugin.
views_plugin_exposed_form::options_form public function Provide a form to edit options for this plugin. Overrides views_plugin::options_form 1
views_plugin_exposed_form::option_definition public function Information about options for all kinds of purposes will be held here. Overrides views_object::option_definition 1
views_plugin_exposed_form::post_execute public function
views_plugin_exposed_form::post_render public function
views_plugin_exposed_form::pre_execute public function
views_plugin_exposed_form::pre_render public function 1
views_plugin_exposed_form::query public function Add anything to the query that we might need to. Overrides views_plugin::query 1
views_plugin_exposed_form::reset_form public function