From 1d81be900ffff46b335f6bcd4def1385333e1582 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 11 Nov 2019 16:11:20 +1300 Subject: [PATCH] Update url handling of select fields --- CRM/Core/Form/Search.php | 9 +++++++-- CRM/Event/Form/Search.php | 30 ++++++------------------------ CRM/Member/Form/Search.php | 19 +------------------ 3 files changed, 14 insertions(+), 44 deletions(-) diff --git a/CRM/Core/Form/Search.php b/CRM/Core/Form/Search.php index c4ea8a2599..a2fb332f81 100644 --- a/CRM/Core/Form/Search.php +++ b/CRM/Core/Form/Search.php @@ -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]); } /** diff --git a/CRM/Event/Form/Search.php b/CRM/Event/Form/Search.php index 5efeee1262..2c2d827914 100644 --- a/CRM/Event/Form/Search.php +++ b/CRM/Event/Form/Search.php @@ -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 * diff --git a/CRM/Member/Form/Search.php b/CRM/Member/Form/Search.php index f9b9a22f5a..9b31de1bd5 100644 --- a/CRM/Member/Form/Search.php +++ b/CRM/Member/Form/Search.php @@ -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(); -- 2.25.1