From 5f1bf12fafcb0f44555caa6253e988c9e4b4d68d Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 3 Oct 2019 08:19:13 +0200 Subject: [PATCH] Consolidate getFormValues on contribution search This consolidates 2 places where formValues are determined on contribution search. In one place force is handled in the other retrieving from the form is handled. It seems Ok to handle both in one place & call that. This might help iron on some glitches Monish is hitting on #15370 We should probably add saved search retrieval in too To confirm this works use this url civicrm/contribute/search?reset=1&reset=1&sort_name=p&receive_date_high=20180101&force=1 - it should filter. If you add another criteria to the form afterwards the url criteria should be present on the form from the url & the new one should also be respected. If you actively remove the url criteria on the form it is ignored in the search --- CRM/Contribute/Form/Search.php | 9 +-------- CRM/Core/Form/Search.php | 28 +++++++++++++++++++++------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/CRM/Contribute/Form/Search.php b/CRM/Contribute/Form/Search.php index fe892ed801..6fdb263afb 100644 --- a/CRM/Contribute/Form/Search.php +++ b/CRM/Contribute/Form/Search.php @@ -86,14 +86,7 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search { $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'); - } + $this->_formValues = $this->getFormValues(); //membership ID $memberShipId = CRM_Utils_Request::retrieve('memberId', 'Positive', $this); diff --git a/CRM/Core/Form/Search.php b/CRM/Core/Form/Search.php index 7fab1da759..fed155bbff 100644 --- a/CRM/Core/Form/Search.php +++ b/CRM/Core/Form/Search.php @@ -129,7 +129,7 @@ class CRM_Core_Form_Search extends CRM_Core_Form { * * @return array|NULL * reference to the array of default values - * @throws \Exception + * @throws \CRM_Core_Exception */ public function setDefaultValues() { $defaults = (array) $this->_formValues; @@ -145,12 +145,7 @@ class CRM_Core_Form_Search extends CRM_Core_Form { * @throws \Exception */ protected function setFormValues() { - if (!empty($_POST) && !$this->_force) { - $this->_formValues = $this->controller->exportValues($this->_name); - } - elseif ($this->_force) { - $this->_formValues = $this->setDefaultValues(); - } + $this->_formValues = $this->getFormValues(); $this->convertTextStringsToUseLikeOperator(); } @@ -477,4 +472,23 @@ class CRM_Core_Form_Search extends CRM_Core_Form { } } + /** + * Get the form values. + * + * @todo consolidate with loadFormValues() + * + * @return array + * + * @throws \CRM_Core_Exception + */ + protected function getFormValues() { + if (!empty($_POST) && !$this->_force) { + return $this->controller->exportValues($this->_name); + } + if ($this->_force) { + return $this->setDefaultValues(); + } + return (array) $this->get('formValues'); + } + } -- 2.25.1