You are here

function views_plugin_exposed_form::exposed_form_alter in Views (for Drupal 7) 6.3

Same name and namespace in other branches
  1. 7.3 plugins/views_plugin_exposed_form.inc \views_plugin_exposed_form::exposed_form_alter()

File

plugins/views_plugin_exposed_form.inc, line 187

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'],
    );
    $first_sort = reset($this->view->sort);
    $form['sort_order'] = array(
      '#type' => 'select',
      '#options' => $sort_order,
      '#title' => t('Order'),
      '#default_value' => $first_sort->options['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'] .= ' ctools-auto-submit-full-form';
    $form['submit']['#attributes']['class'] = 'ctools-use-ajax ctools-auto-submit-click';
    ctools_add_js('auto-submit');
    if (!empty($this->options['autosubmit_hide'])) {
      $form['submit']['#attributes']['class'] .= ' js-hide';
    }
  }
}