From 9637ef7d87a3c5909b251db8fbac7bd36bf3491b Mon Sep 17 00:00:00 2001
From: dereine <dereine@99340.no-reply.drupal.org>
Date: Tue, 2 Oct 2012 15:38:58 -0400
Subject: [PATCH] Issue #948198 by dawehner, Darren Oh: Added an option not to
 display 'order' selectbox when using Exposed sort criterion.

---
 .../exposed_form/ExposedFormPluginBase.php    | 32 +++++++++++++++----
 1 file changed, 26 insertions(+), 6 deletions(-)

diff --git a/lib/Drupal/views/Plugin/views/exposed_form/ExposedFormPluginBase.php b/lib/Drupal/views/Plugin/views/exposed_form/ExposedFormPluginBase.php
index 4e7254a7b614..c583d65ee004 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;
-- 
GitLab