diff --git a/lib/Drupal/views/Plugin/views/exposed_form/ExposedFormPluginBase.php b/lib/Drupal/views/Plugin/views/exposed_form/ExposedFormPluginBase.php index 4e7254a7b6145fb27077ec869e8b347ec9da1738..c583d65ee004aac3f7092d3151a174d882c75c47 100644 --- a/lib/Drupal/views/Plugin/views/exposed_form/ExposedFormPluginBase.php +++ b/lib/Drupal/views/Plugin/views/exposed_form/ExposedFormPluginBase.php @@ -52,6 +52,7 @@ protected function defineOptions() { $options['reset_button'] = array('default' => FALSE, 'bool' => TRUE); $options['reset_button_label'] = array('default' => 'Reset', 'translatable' => TRUE); $options['exposed_sorts_label'] = array('default' => 'Sort by', 'translatable' => TRUE); + $options['expose_sort_order'] = array('default' => TRUE, 'bool' => TRUE); $options['sort_asc_label'] = array('default' => 'Asc', 'translatable' => TRUE); $options['sort_desc_label'] = array('default' => 'Desc', 'translatable' => TRUE); return $options; @@ -95,12 +96,24 @@ public function buildOptionsForm(&$form, &$form_state) { '#required' => TRUE, ); + $form['expose_sort_order'] = array( + '#type' => 'checkbox', + '#title' => t('Expose sort order'), + '#description' => t('Allow the user to choose the sort order. If sort order is not exposed, the sort criteria settings for each sort will determine its order.'), + '#default_value' => $this->options['expose_sort_order'], + ); + $form['sort_asc_label'] = array( '#type' => 'textfield', '#title' => t('Ascending'), '#description' => t('Text to use when exposed sort is ordered ascending.'), '#default_value' => $this->options['sort_asc_label'], '#required' => TRUE, + '#states' => array( + 'visible' => array( + 'input[name="exposed_form_options[expose_sort_order]"]' => array('checked' => TRUE), + ), + ), ); $form['sort_desc_label'] = array( @@ -109,6 +122,11 @@ public function buildOptionsForm(&$form, &$form_state) { '#description' => t('Text to use when exposed sort is ordered descending.'), '#default_value' => $this->options['sort_desc_label'], '#required' => TRUE, + '#states' => array( + 'visible' => array( + 'input[name="exposed_form_options[expose_sort_order]"]' => array('checked' => TRUE), + ), + ), ); } @@ -226,12 +244,14 @@ function exposed_form_alter(&$form, &$form_state) { $form_state['input']['sort_by'] = array_shift($keys); } - $form['sort_order'] = array( - '#type' => 'select', - '#options' => $sort_order, - '#title' => t('Order'), - '#default_value' => $default_sort_order, - ); + 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;