1 views_plugin_exposed_form.inc views_plugin_exposed_form::exposed_form_alter(&$form, &$form_state)

File

core/modules/views/plugins/views_plugin_exposed_form.inc, line 217
Definition of views_plugin_exposed_form.

Class

views_plugin_exposed_form
The base plugin to handle exposed filter forms.

Code

function exposed_form_alter(&$form, &$form_state) {
  if (!empty($this->options['reset_button'])) {
    $form['reset'] = array(
      '#value' => $this->options['reset_button_label'],
      '#type' => 'submit',
    );
  }

  $form['submit']['#value'] = $this->options['submit_button'];
  // Check if there is exposed sorts for this view
  $exposed_sorts = array();
  foreach ($this->view->sort as $id => $handler) {
    if ($handler->can_expose() && $handler->is_exposed()) {
      $exposed_sorts[$id] = check_plain($handler->options['expose']['label']);
    }
  }

  if (count($exposed_sorts)) {
    $form['sort_by'] = array(
      '#type' => 'select',
      '#options' => $exposed_sorts,
      '#title' => $this->options['exposed_sorts_label'],
    );
    $sort_order = array(
      'ASC' => $this->options['sort_asc_label'],
      'DESC' => $this->options['sort_desc_label'],
    );
    if (isset($form_state['input']['sort_by']) && isset($this->view->sort[$form_state['input']['sort_by']])) {
      $default_sort_order = $this->view->sort[$form_state['input']['sort_by']]->options['order'];
    }
    else {
      $first_sort = reset($this->view->sort);
      $default_sort_order = $first_sort->options['order'];
    }

    if (!isset($form_state['input']['sort_by'])) {
      $keys = array_keys($exposed_sorts);
      $form_state['input']['sort_by'] = array_shift($keys);
    }

    if ($this->options['expose_sort_order']) {
      $form['sort_order'] = array(
        '#type' => 'select',
        '#options' => $sort_order,
        '#title' => t('Order'),
        '#default_value' => $default_sort_order,
      );
    }
    $form['submit']['#weight'] = 10;
    if (isset($form['reset'])) {
      $form['reset']['#weight'] = 10;
    }
  }

  $pager = $this->view->display_handler->get_plugin('pager');
  if ($pager) {
    $pager->exposed_form_alter($form, $form_state);
    $form_state['pager_plugin'] = $pager;
  }


  // Apply autosubmit values.
  if (!empty($this->options['autosubmit'])) {
    $form['#attributes']['class'][] = 'autosubmit-full-form';
    $form['submit']['#attributes']['class'][] = 'autosubmit-click';
    $form['#attached']['library'][] = array('system', 'backdrop.autosubmit');

    if (!empty($this->options['autosubmit_hide'])) {
      $form['submit']['#attributes']['class'][] = 'js-hide';
    }
  }
}