function views_plugin_exposed_form::exposed_form_alter
File
-
plugins/
views_plugin_exposed_form.inc, line 234
Class
- views_plugin_exposed_form
- The base plugin to handle exposed filter forms.
Code
public 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)) {
if (isset($form_state['input']['sort_by'])) {
$sort_by = $form_state['input']['sort_by'];
}
else {
$keys = array_keys($exposed_sorts);
$sort_by = array_shift($keys);
}
if (isset($form_state['input']['sort_order'])) {
$sort_order = $form_state['input']['sort_order'];
}
elseif (isset($this->view->sort[$sort_by])) {
$sort_order = $this->view->sort[$sort_by]->options['order'];
}
else {
$first_sort = reset($this->view->sort);
$sort_order = $first_sort->options['order'];
}
if (!isset($form_state['input']['sort_by'])) {
$form_state['input']['sort_by'] = $sort_by;
}
if (!isset($form_state['input']['sort_order'])) {
$form_state['input']['sort_order'] = $sort_order;
}
$form['sort_by'] = array(
'#type' => 'select',
'#options' => $exposed_sorts,
'#title' => $this->options['exposed_sorts_label'],
'#default_value' => $sort_by,
);
$sort_options = array(
'ASC' => $this->options['sort_asc_label'],
'DESC' => $this->options['sort_desc_label'],
);
if ($this->options['expose_sort_order']) {
$form['sort_order'] = array(
'#type' => 'select',
'#options' => $sort_options,
'#title' => t('Order', array(), array(
'context' => 'Sort order',
)),
'#default_value' => $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 = array_merge_recursive($form, array(
'#attributes' => array(
'class' => array(
'ctools-auto-submit-full-form',
),
),
));
$form['submit']['#attributes']['class'][] = 'ctools-use-ajax';
$form['submit']['#attributes']['class'][] = 'ctools-auto-submit-click';
$form['#attached']['js'][] = drupal_get_path('module', 'ctools') . '/js/auto-submit.js';
if (!empty($this->options['autosubmit_hide'])) {
$form['submit']['#attributes']['class'][] = 'js-hide';
}
}
}