Merge pull request #18591 from eileenmcnaughton/search
authorcolemanw <coleman@civicrm.org>
Fri, 25 Sep 2020 22:59:54 +0000 (18:59 -0400)
committerGitHub <noreply@github.com>
Fri, 25 Sep 2020 22:59:54 +0000 (18:59 -0400)
[REF] Consolidate retrieval of searchFormValues

18 files changed:
CRM/Activity/Form/Task.php
CRM/Case/Form/Search.php
CRM/Contact/Form/Search/Advanced.php
CRM/Contact/Form/Search/Basic.php
CRM/Contact/Form/Search/Builder.php
CRM/Contact/Form/Search/Custom.php
CRM/Contact/Form/Task.php
CRM/Contribute/Form/Search.php
CRM/Contribute/Form/Task.php
CRM/Core/Form/Task.php
CRM/Event/Form/Search.php
CRM/Event/Form/Task.php
CRM/Export/Form/Select.php
CRM/Grant/Form/Task.php
CRM/Mailing/Form/Task.php
CRM/Member/Form/Search.php
CRM/Member/Form/Task.php
tests/phpunit/CRM/Contribute/Form/TaskTest.php

index 462499c38fd338b1bb705f2f9e200413cd1c96e7..470e3692e8df4ac3af5ba8048516d4bf8cce61ca 100644 (file)
@@ -38,14 +38,14 @@ class CRM_Activity_Form_Task extends CRM_Core_Form_Task {
   /**
    * Common pre-process function.
    *
-   * @param CRM_Core_Form $form
+   * @param \CRM_Core_Form_Task $form
    *
    * @throws \CRM_Core_Exception
    */
   public static function preProcessCommon(&$form) {
     $form->_activityHolderIds = [];
 
-    $values = $form->controller->exportValues($form->get('searchFormName'));
+    $values = $form->getSearchFormValues();
 
     $form->_task = $values['task'];
     $activityTasks = CRM_Activity_Task::tasks();
index b22ab8c08e97dbbb8884affb03d974a3c61c8eec..d3ba7a07c4d7d029eecb2fb5edbc7818e10dd494 100644 (file)
@@ -58,6 +58,9 @@ class CRM_Case_Form_Search extends CRM_Core_Form_Search {
    * Processing needed for buildForm and later.
    */
   public function preProcess() {
+    // SearchFormName is deprecated & to be removed - the replacement is for the task to
+    // call $this->form->getSearchFormValues()
+    // A couple of extensions use it.
     $this->set('searchFormName', 'Search');
 
     //check for civicase access.
index e579c743316625c7ba92096d5ce68b0b44eed638..95e981a63dad963c04a05539bb6f38902c17d513 100644 (file)
@@ -24,6 +24,9 @@ class CRM_Contact_Form_Search_Advanced extends CRM_Contact_Form_Search {
    * Processing needed for buildForm and later.
    */
   public function preProcess() {
+    // SearchFormName is deprecated & to be removed - the replacement is for the task to
+    // call $this->form->getSearchFormValues()
+    // A couple of extensions use it.
     $this->set('searchFormName', 'Advanced');
 
     parent::preProcess();
index c1e84382319ffdfe400087c705c29717c939118d..6deec9e2a44dd3f4f396de3e6a80af0bdca2132b 100644 (file)
@@ -117,6 +117,9 @@ class CRM_Contact_Form_Search_Basic extends CRM_Contact_Form_Search {
    * Processing needed for buildForm and later.
    */
   public function preProcess() {
+    // SearchFormName is deprecated & to be removed - the replacement is for the task to
+    // call $this->form->getSearchFormValues()
+    // A couple of extensions use it.
     $this->set('searchFormName', 'Basic');
 
     parent::preProcess();
index fc51f6580d352d3491d6ec85f2ac9e7b5e0e08ae..0eccbcb5049f88909a62d873d2544a803c5cd6c1 100644 (file)
@@ -38,6 +38,9 @@ class CRM_Contact_Form_Search_Builder extends CRM_Contact_Form_Search {
    * Build the form object.
    */
   public function preProcess() {
+    // SearchFormName is deprecated & to be removed - the replacement is for the task to
+    // call $this->form->getSearchFormValues()
+    // A couple of extensions use it.
     $this->set('searchFormName', 'Builder');
 
     $this->set('context', 'builder');
index cfc78ef8355b7a73c972547c30a25363667a4d91..d2b4fd4cdd393aa278c7bcfbfc4caca7e7d772a1 100644 (file)
@@ -19,6 +19,9 @@ class CRM_Contact_Form_Search_Custom extends CRM_Contact_Form_Search {
   protected $_customClass = NULL;
 
   public function preProcess() {
+    // SearchFormName is deprecated & to be removed - the replacement is for the task to
+    // call $this->form->getSearchFormValues()
+    // A couple of extensions use it.
     $this->set('searchFormName', 'Custom');
 
     $this->set('context', 'custom');
index a7bd173701ef4be7d70aa5e8eb0ace11fdb3c27d..8263094ea0ecf90bee64c99f55953149bdcb6cdb 100644 (file)
@@ -112,7 +112,7 @@ class CRM_Contact_Form_Task extends CRM_Core_Form_Task {
       $fragment .= '/custom';
     }
     if (!$isStandAlone) {
-      self::$_searchFormValues = $form->getFormValues();
+      self::$_searchFormValues = $form->getSearchFormValues();
     }
 
     //set the user context for redirection of task actions
index 341c54c868d492bafd815c28bd463c1d6feb4bb9..866c178848dffcb0e06980d53c9bf788d2f36475 100644 (file)
@@ -61,6 +61,9 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search {
    * @throws \CRM_Core_Exception
    */
   public function preProcess() {
+    // SearchFormName is deprecated & to be removed - the replacement is for the task to
+    // call $this->form->getSearchFormValues()
+    // A couple of extensions use it.
     $this->set('searchFormName', 'Search');
 
     $this->_actionButtonName = $this->getButtonName('next', 'action');
index 16d61166670f2fad61b8a996f481ced123d99d96..ce5b071fa9bbe61631cd436872e3f16c8e52bb2f 100644 (file)
@@ -50,12 +50,14 @@ class CRM_Contribute_Form_Task extends CRM_Core_Form_Task {
   }
 
   /**
-   * @param CRM_Core_Form $form
+   * @param \CRM_Core_Form_Task $form
+   *
+   * @throws \CRM_Core_Exception
    */
   public static function preProcessCommon(&$form) {
     $form->_contributionIds = [];
 
-    $values = $form->controller->exportValues($form->get('searchFormName'));
+    $values = $form->getSearchFormValues();
 
     $form->_task = $values['task'] ?? NULL;
     $contributeTasks = CRM_Contribute_Task::tasks();
index a3bde1d8b668501bd481fe23dfbe7feee44dc6ac..65a105d3878cc0215f6582d1d047ba75d4257b3c 100644 (file)
@@ -92,7 +92,7 @@ abstract class CRM_Core_Form_Task extends CRM_Core_Form {
   public static function preProcessCommon(&$form) {
     $form->_entityIds = [];
 
-    $searchFormValues = $form->controller->exportValues($form->get('searchFormName'));
+    $searchFormValues = $form->getSearchFormValues();
 
     $form->_task = $searchFormValues['task'];
     $className = 'CRM_' . ucfirst($form::$entityShortname) . '_Task';
@@ -256,7 +256,7 @@ SELECT contact_id
    *
    * @return array
    */
-  public function getFormValues() {
+  public function getSearchFormValues() {
     if ($this->_action === CRM_Core_Action::ADVANCED) {
       return $this->controller->exportValues('Advanced');
     }
@@ -266,6 +266,9 @@ SELECT contact_id
     if ($this->_action == CRM_Core_Action::COPY) {
       return $this->controller->exportValues('Custom');
     }
+    if ($this->get('entity') !== 'Contact') {
+      return $this->controller->exportValues('Search');
+    }
     return $this->controller->exportValues('Basic');
   }
 
index 30001106871355690a3bc30630499c7825466323..ac4404ca6de11e530b1b2f84dcebfa42bd935a0a 100644 (file)
@@ -79,6 +79,9 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search {
    * @throws \CiviCRM_API3_Exception
    */
   public function preProcess() {
+    // SearchFormName is deprecated & to be removed - the replacement is for the task to
+    // call $this->form->getSearchFormValues()
+    // A couple of extensions use it.
     $this->set('searchFormName', 'Search');
 
     /**
index 18962108a61cfc379596c8c0077e2ff1fb4f962d..ddb8953815b088d59998b8cfd2ecbace0f89ba75 100644 (file)
@@ -40,12 +40,12 @@ class CRM_Event_Form_Task extends CRM_Core_Form_Task {
   }
 
   /**
-   * @param CRM_Core_Form $form
+   * @param CRM_Core_Form_Task $form
    */
   public static function preProcessCommon(&$form) {
     $form->_participantIds = [];
 
-    $values = $form->controller->exportValues($form->get('searchFormName'));
+    $values = $form->getSearchFormValues();
 
     $form->_task = $values['task'];
     $tasks = CRM_Event_Task::permissionedTaskTitles(CRM_Core_Permission::getPermission());
index abc1f3b2deb6514ded58b9931a045737766d2adb..4772536ab763daa72364af9274741b74638960f5 100644 (file)
@@ -108,24 +108,7 @@ class CRM_Export_Form_Select extends CRM_Core_Form_Task {
       $this::$tableName = CRM_Core_DAO_AllCoreTables::getTableForClass(CRM_Core_DAO_AllCoreTables::getFullName($this->getDAOName()));
     }
 
-    // get the submitted values based on search
-    if ($this->_action == CRM_Core_Action::ADVANCED) {
-      $values = $this->controller->exportValues('Advanced');
-    }
-    elseif ($this->_action == CRM_Core_Action::PROFILE) {
-      $values = $this->controller->exportValues('Builder');
-    }
-    elseif ($this->_action == CRM_Core_Action::COPY) {
-      $values = $this->controller->exportValues('Custom');
-    }
-    else {
-      if ($entityShortname !== 'Contact') {
-        $values = $this->controller->exportValues('Search');
-      }
-      else {
-        $values = $this->controller->exportValues('Basic');
-      }
-    }
+    $values = $this->getSearchFormValues();
 
     $count = 0;
     $this->_matchingContacts = FALSE;
index b983cec3d72afac8c84b7804bc115370af162b88..3917ac01f88cc3e68452f629b748462a8655268a 100644 (file)
@@ -34,12 +34,14 @@ class CRM_Grant_Form_Task extends CRM_Core_Form_Task {
   }
 
   /**
-   * @param CRM_Core_Form $form
+   * @param \CRM_Core_Form_Task $form
+   *
+   * @throws \CRM_Core_Exception
    */
   public static function preProcessCommon(&$form) {
     $form->_grantIds = [];
 
-    $values = $form->controller->exportValues($form->get('searchFormName'));
+    $values = $form->getSearchFormValues();
 
     $form->_task = $values['task'];
     $tasks = CRM_Grant_Task::tasks();
index 4a84746aaaba6479e80500081dbbff1f98eb6a76..f7f37eee39cd509724e0ba2efac1ff87255c8b20 100644 (file)
@@ -29,10 +29,12 @@ class CRM_Mailing_Form_Task extends CRM_Core_Form_Task {
   }
 
   /**
-   * @param CRM_Core_Form $form
+   * @param \CRM_Core_Form_Task $form
+   *
+   * @throws \CRM_Core_Exception
    */
   public static function preProcessCommon(&$form) {
-    $values = $form->controller->exportValues($form->get('searchFormName'));
+    $values = $form->getSearchFormValues();
 
     $form->_task = $values['task'] ?? NULL;
     $mailingTasks = CRM_Mailing_Task::tasks();
index fc0ba94de0b5726dfd686625ffaba02c2277f031..dd937142ff660f6c8752cd2ec7e52b3e541722e4 100644 (file)
@@ -63,6 +63,9 @@ class CRM_Member_Form_Search extends CRM_Core_Form_Search {
    * @throws \CiviCRM_API3_Exception
    */
   public function preProcess() {
+    // SearchFormName is deprecated & to be removed - the replacement is for the task to
+    // call $this->form->getSearchFormValues()
+    // A couple of extensions use it.
     $this->set('searchFormName', 'Search');
 
     $this->_actionButtonName = $this->getButtonName('next', 'action');
index 5f5791d01ab0f3019f7f4f976364c6f5c5485101..86eda194ddacbd445f408cf3bafecf4e0775ae53 100644 (file)
@@ -41,14 +41,14 @@ class CRM_Member_Form_Task extends CRM_Core_Form_Task {
   }
 
   /**
-   * @param CRM_Core_Form $form
+   * @param \CRM_Core_Form_Task $form
    *
    * @throws \CRM_Core_Exception
    */
   public static function preProcessCommon(&$form) {
     $form->_memberIds = [];
 
-    $values = $form->controller->exportValues($form->get('searchFormName'));
+    $values = $form->getSearchFormValues();
 
     $form->_task = $values['task'];
     $tasks = CRM_Member_Task::permissionedTaskTitles(CRM_Core_Permission::getPermission());
index acd140f5bb1775782c3f46051a01ff030963c27c..51605fe923c3a01a46469dc72db57d7d11496c49 100644 (file)
@@ -66,8 +66,7 @@ class CRM_Contribute_Form_TaskTest extends CiviUnitTestCase {
     }
 
     // Assert contribIds are returned in a sorted order.
-    $form = new CRM_Contribute_Form_Task();
-    $form->controller = new CRM_Core_Controller();
+    $form = $this->getFormObject('CRM_Contribute_Form_Task', [], 'Search');
     foreach ($fields as $val) {
       $form->set(CRM_Utils_Sort::SORT_ORDER, "`{$val}` asc");
       CRM_Contribute_Form_Task::preProcessCommon($form);