From 986ac53f2addee153934d381c61ed3ffd73ab929 Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 18 Sep 2020 14:25:34 +1200 Subject: [PATCH] [Ref] Extract getFormValues Digging into this is seems the is always an object that inherits from this class It is called statically primarily because the export task does not have subclasses per form & does not know what variant it's passing in. However, we can move functions onto the CRM_Contact_Form_Task class as non-static functions and call them form form-> however unintuitive that seems. I am trying to clean up the structure such that we can move on from the static method but decided I should tackle this function a little first. To test try doing an export from any search & this is called in static mode (same goes for any task but the path is less ambiguous) --- CRM/Contact/Form/Task.php | 15 ++++++--------- CRM/Core/Form/Task.php | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/CRM/Contact/Form/Task.php b/CRM/Contact/Form/Task.php index 2f7695dc7d..a7bd173701 100644 --- a/CRM/Contact/Form/Task.php +++ b/CRM/Contact/Form/Task.php @@ -78,7 +78,7 @@ class CRM_Contact_Form_Task extends CRM_Core_Form_Task { /** * Common pre-processing function. * - * @param CRM_Core_Form $form + * @param \CRM_Core_Form_Task $form * * @throws \CRM_Core_Exception */ @@ -88,7 +88,7 @@ class CRM_Contact_Form_Task extends CRM_Core_Form_Task { $isStandAlone = in_array('task', $form->urlPath) || in_array('standalone', $form->urlPath); if ($isStandAlone) { - list($form->_task, $title) = CRM_Contact_Task::getTaskAndTitleByClass(get_class($form)); + [$form->_task, $title] = CRM_Contact_Task::getTaskAndTitleByClass(get_class($form)); if (!array_key_exists($form->_task, CRM_Contact_Task::permissionedTaskTitles(CRM_Core_Permission::getPermission()))) { CRM_Core_Error::statusBounce(ts('You do not have permission to access this page.')); } @@ -103,19 +103,16 @@ class CRM_Contact_Form_Task extends CRM_Core_Form_Task { // we'll need to get fv from either search or adv search in the future $fragment = 'search'; if ($form->_action == CRM_Core_Action::ADVANCED) { - self::$_searchFormValues = $form->controller->exportValues('Advanced'); $fragment .= '/advanced'; } elseif ($form->_action == CRM_Core_Action::PROFILE) { - self::$_searchFormValues = $form->controller->exportValues('Builder'); $fragment .= '/builder'; } elseif ($form->_action == CRM_Core_Action::COPY) { - self::$_searchFormValues = $form->controller->exportValues('Custom'); $fragment .= '/custom'; } - elseif (!$isStandAlone) { - self::$_searchFormValues = $form->controller->exportValues('Basic'); + if (!$isStandAlone) { + self::$_searchFormValues = $form->getFormValues(); } //set the user context for redirection of task actions @@ -125,12 +122,12 @@ class CRM_Contact_Form_Task extends CRM_Core_Form_Task { $urlParams .= "&qfKey=$qfKey"; } - $cacheKey = "civicrm search {$qfKey}"; - $url = CRM_Utils_System::url('civicrm/contact/' . $fragment, $urlParams); $session = CRM_Core_Session::singleton(); $session->replaceUserContext($url); + $cacheKey = "civicrm search {$qfKey}"; + $form->_task = self::$_searchFormValues['task'] ?? NULL; $crmContactTaskTasks = CRM_Contact_Task::taskTitles(); $form->assign('taskName', CRM_Utils_Array::value($form->_task, $crmContactTaskTasks)); diff --git a/CRM/Core/Form/Task.php b/CRM/Core/Form/Task.php index 67ca0537ad..a3bde1d8b6 100644 --- a/CRM/Core/Form/Task.php +++ b/CRM/Core/Form/Task.php @@ -251,4 +251,22 @@ SELECT contact_id return ''; } + /** + * Get the submitted values for the form. + * + * @return array + */ + public function getFormValues() { + if ($this->_action === CRM_Core_Action::ADVANCED) { + return $this->controller->exportValues('Advanced'); + } + if ($this->_action === CRM_Core_Action::PROFILE) { + return $this->controller->exportValues('Builder'); + } + if ($this->_action == CRM_Core_Action::COPY) { + return $this->controller->exportValues('Custom'); + } + return $this->controller->exportValues('Basic'); + } + } -- 2.25.1