Update url handling of select fields
authoreileen <emcnaughton@wikimedia.org>
Mon, 11 Nov 2019 03:11:20 +0000 (16:11 +1300)
committereileen <emcnaughton@wikimedia.org>
Mon, 11 Nov 2019 03:25:59 +0000 (16:25 +1300)
CRM/Core/Form/Search.php
CRM/Event/Form/Search.php
CRM/Member/Form/Search.php

index c4ea8a259940579fc321911d818dbf5880350c05..a2fb332f8163e79f3d5145a5e9cb9893abf36e6a 100644 (file)
@@ -304,7 +304,12 @@ class CRM_Core_Form_Search extends CRM_Core_Form {
       if (empty($_POST[$fieldName])) {
         $value = CRM_Utils_Request::retrieveValue($fieldName, $this->getValidationTypeForField($entity, $fieldName), NULL, NULL, 'GET');
         if ($value !== NULL) {
-          $defaults[$fieldName] = $value;
+          if ($fieldSpec['html']['type'] === 'Select') {
+            $defaults[$fieldName] = explode(',', $value);
+          }
+          else {
+            $defaults[$fieldName] = $value;
+          }
         }
         if ($fieldSpec['type'] === CRM_Utils_Type::T_DATE || ($fieldSpec['type'] === CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME)) {
           $low = CRM_Utils_Request::retrieveValue($fieldName . '_low', 'Timestamp', NULL, NULL, 'GET');
@@ -393,7 +398,7 @@ class CRM_Core_Form_Search extends CRM_Core_Form {
       $title,
       CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')
     );
-    $this->searchFieldMetadata['Contact']['sort_name'] = ['name' => 'sort_name', 'title' => $title, 'type' => CRM_Utils_Type::T_STRING];
+    $this->searchFieldMetadata['Contact']['sort_name'] = array_merge(CRM_Contact_DAO_Contact::fields()['sort_name'], ['name' => 'sort_name', 'title' => $title, 'type' => CRM_Utils_Type::T_STRING]);
   }
 
   /**
index 5efeee126270b49d3e0e4719fb9dd1b41f448aab..2c2d82791493c0aff34467f4d6ecc8afc66ca3cd 100644 (file)
@@ -90,6 +90,9 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search {
    * Processing needed for buildForm and later.
    *
    * @return void
+   *
+   * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
    */
   public function preProcess() {
     $this->set('searchFormName', 'Search');
@@ -102,13 +105,7 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search {
 
     $this->_done = FALSE;
 
-    $this->loadStandardSearchOptionsFromUrl();
-    $this->loadFormValues();
-
-    if ($this->_force) {
-      $this->postProcess();
-      $this->set('force', 0);
-    }
+    parent::preProcess();
 
     $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, ['event_id']);
     $selector = new CRM_Event_Selector_Search($this->_queryParams,
@@ -374,6 +371,7 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search {
    * @param
    *
    * @return void
+   * @throws \CRM_Core_Exception
    */
   public function postProcess() {
     if ($this->_done) {
@@ -381,16 +379,7 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search {
     }
 
     $this->_done = TRUE;
-    $formValues = [];
-
-    if (!empty($_POST)) {
-      $formValues = $this->controller->exportValues($this->_name);
-      CRM_Contact_BAO_Query::processSpecialFormValue($this->_formValues, ['participant_status_id']);
-    }
-
-    if (empty($formValues)) {
-      $formValues = $this->controller->exportValues($this->_name);
-    }
+    $formValues = $this->getFormValues();
 
     $this->submit($formValues);
   }
@@ -466,13 +455,6 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search {
     }
   }
 
-  /**
-   * @return null
-   */
-  public function getFormValues() {
-    return NULL;
-  }
-
   /**
    * Return a descriptive name for the page, used in wizard header
    *
index f9b9a22f5a35af9c01f1ec71cc61024cba997dc1..9b31de1bd57e3eb609080d56ce65a8b607d8ae0e 100644 (file)
@@ -86,23 +86,7 @@ class CRM_Member_Form_Search extends CRM_Core_Form_Search {
 
     $this->_done = FALSE;
 
-    $this->loadStandardSearchOptionsFromUrl();
-
-    // get user submitted values
-    // get it from controller only if form has been submitted, else preProcess has set this
-    if (!empty($_POST)) {
-      $this->_formValues = $this->controller->exportValues($this->_name);
-    }
-    else {
-      $this->_formValues = $this->get('formValues');
-    }
-
-    if ($this->_force) {
-      $this->addSearchFieldMetadata(['Membership' => CRM_Member_BAO_Query::getSearchFieldMetadata()]);
-      $this->addFormFieldsFromMetadata();
-      $this->postProcess();
-      $this->set('force', 0);
-    }
+    parent::preProcess();
 
     $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, $this->entityReferenceFields);
     $selector = new CRM_Member_Selector_Search($this->_queryParams,
@@ -241,7 +225,6 @@ class CRM_Member_Form_Search extends CRM_Core_Form_Search {
 
     $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, $this->entityReferenceFields);
 
-    $this->set('formValues', $this->_formValues);
     $this->set('queryParams', $this->_queryParams);
 
     $buttonName = $this->controller->getButtonName();