You are here

function entityreference_view_widget_plugin_exposed_form::exposed_form_alter in Entity Reference View Widget 7

Overrides views_plugin_exposed_form::exposed_form_alter

File

views/entityreference_view_widget_plugin_exposed_form.inc, line 58

Class

entityreference_view_widget_plugin_exposed_form
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.

Code

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();
}