From f90f8d32b9f76349f77a6e58bafa18c6e1d9ae5b Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 31 Jul 2019 21:44:57 +1200 Subject: [PATCH] Extend contribute search url parsing to advanced search --- CRM/Contact/Form/Search.php | 14 +++++++++++++- CRM/Contribute/Form/Search.php | 2 -- CRM/Core/Form/Search.php | 7 ++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CRM/Contact/Form/Search.php b/CRM/Contact/Form/Search.php index a9d929a48d..0d854ff10f 100644 --- a/CRM/Contact/Form/Search.php +++ b/CRM/Contact/Form/Search.php @@ -731,7 +731,7 @@ class CRM_Contact_Form_Search extends CRM_Core_Form_Search { $controller->setDynamicAction($setDynamic); if ($this->_force) { - + $this->loadMetadata(); $this->postProcess(); /* @@ -909,4 +909,16 @@ class CRM_Contact_Form_Search extends CRM_Core_Form_Search { return ts('Search'); } + /** + * Load metadata for fields on the form. + * + * @throws \CiviCRM_API3_Exception + */ + protected function loadMetadata() { + // @todo - check what happens if the person does not have 'access civicontribute' - make sure they + // can't by pass acls by passing search criteria in the url. + $this->addSearchFieldMetadata(['Contribution' => CRM_Contribute_BAO_Query::getSearchFieldMetadata()]); + $this->addSearchFieldMetadata(['ContributionRecur' => CRM_Contribute_BAO_ContributionRecur::getContributionRecurSearchFieldMetadata()]); + } + } diff --git a/CRM/Contribute/Form/Search.php b/CRM/Contribute/Form/Search.php index f3aa40248b..fe892ed801 100644 --- a/CRM/Contribute/Form/Search.php +++ b/CRM/Contribute/Form/Search.php @@ -414,8 +414,6 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search { if (!$this->_force) { return; } - // Start by loading url defaults. - $this->_formValues = $this->setDefaultValues(); $status = CRM_Utils_Request::retrieve('status', 'String'); if ($status) { diff --git a/CRM/Core/Form/Search.php b/CRM/Core/Form/Search.php index 80ef7ca4f5..eeaf1798b4 100644 --- a/CRM/Core/Form/Search.php +++ b/CRM/Core/Form/Search.php @@ -133,7 +133,7 @@ class CRM_Core_Form_Search extends CRM_Core_Form { */ public function setDefaultValues() { $defaults = (array) $this->_formValues; - foreach (['Contact', $this->getDefaultEntity()] as $entity) { + foreach (array_keys($this->getSearchFieldMetadata()) as $entity) { $defaults = array_merge($this->getEntityDefaults($entity), $defaults); } return $defaults; @@ -141,11 +141,16 @@ class CRM_Core_Form_Search extends CRM_Core_Form { /** * Set the form values based on input and preliminary processing. + * + * @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->convertTextStringsToUseLikeOperator(); } -- 2.25.1