diff --git a/CRM/Contact/Form/Search.php b/CRM/Contact/Form/Search.php index a9d929a48d55..0d854ff10f93 100644 --- a/CRM/Contact/Form/Search.php +++ b/CRM/Contact/Form/Search.php @@ -731,7 +731,7 @@ public function preProcess() { $controller->setDynamicAction($setDynamic); if ($this->_force) { - + $this->loadMetadata(); $this->postProcess(); /* @@ -909,4 +909,16 @@ public function getTitle() { 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 f3aa40248b8a..fe892ed80159 100644 --- a/CRM/Contribute/Form/Search.php +++ b/CRM/Contribute/Form/Search.php @@ -414,8 +414,6 @@ public function fixFormValues() { 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 80ef7ca4f5f6..eeaf1798b437 100644 --- a/CRM/Core/Form/Search.php +++ b/CRM/Core/Form/Search.php @@ -133,7 +133,7 @@ public function addSearchFieldMetadata($searchFieldMetadata) { */ 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 @@ public function setDefaultValues() { /** * 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(); }