Extend contribute search url parsing to advanced search
authoreileen <emcnaughton@wikimedia.org>
Wed, 31 Jul 2019 09:44:57 +0000 (21:44 +1200)
committereileen <emcnaughton@wikimedia.org>
Wed, 31 Jul 2019 09:44:57 +0000 (21:44 +1200)
CRM/Contact/Form/Search.php
CRM/Contribute/Form/Search.php
CRM/Core/Form/Search.php

index a9d929a48d55b19637a56f54af68c492d01ee377..0d854ff10f93fdc53094b50bd613478ac0c18115 100644 (file)
@@ -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()]);
+  }
+
 }
index f3aa40248b8aa5e7f57ffef5e34c4153225b0154..fe892ed80159347a45f21ac0314f4486fdf465f8 100644 (file)
@@ -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) {
index 80ef7ca4f5f6d841653b28b0ff3edaa7a884a855..eeaf1798b437170cbab4f3c3771c584552a6f364 100644 (file)
@@ -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();
   }