From d532b68632138a2a6414c744b3511dd46bcbab56 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 18 Jun 2020 16:08:47 -0400 Subject: [PATCH] Export - further cleanup export class to remove unnecessary switch --- CRM/Export/BAO/Export.php | 24 ++++++++++++++++++++++++ CRM/Export/Controller/Standalone.php | 22 ++-------------------- CRM/Export/Form/Select.php | 9 +++++---- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index 5ddf6cb679..83e2fa5ba2 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -25,6 +25,30 @@ class CRM_Export_BAO_Export { // CRM-7675 const EXPORT_ROW_COUNT = 100000; + /** + * Returns a list of exportable entities and their associated component. + * + * Note: Some entities like Contact & Activity are not in components, so + * the export form seems to fudge things and accept the entity name instead of + * component name in those cases. + * + * TODO: Hardcoded list bad. Needs to support extension export pages. + * + * @var string[] + */ + public static function getComponents() { + return [ + 'Contact' => 'Contact', + 'Contribution' => 'Contribute', + 'Membership' => 'Member', + 'Participant' => 'Event', + 'Pledge' => 'Pledge', + 'Case' => 'Case', + 'Grant' => 'Grant', + 'Activity' => 'Activity', + ]; + } + /** * Get the list the export fields. * diff --git a/CRM/Export/Controller/Standalone.php b/CRM/Export/Controller/Standalone.php index abf090cc1a..f4bb8ca534 100644 --- a/CRM/Export/Controller/Standalone.php +++ b/CRM/Export/Controller/Standalone.php @@ -14,25 +14,6 @@ */ class CRM_Export_Controller_Standalone extends CRM_Core_Controller { - /** - * Yet another hardcoded list :( - * - * Very similar to the switch statement in CRM_Export_Form_Select::preProcess - * TODO: Make this extensible for extension export pages. - * - * @var string[] - */ - public $components = [ - 'Contact' => 'Contact', - 'Contribution' => 'Contribute', - 'Membership' => 'Member', - 'Participant' => 'Event', - 'Pledge' => 'Pledge', - 'Case' => 'Case', - 'Grant' => 'Grant', - 'Activity' => 'Activity', - ]; - /** * Class constructor. * @@ -104,7 +85,8 @@ class CRM_Export_Controller_Standalone extends CRM_Core_Controller { * @return string */ public function getComponent() { - return $this->components[$this->getEntity()]; + $components = CRM_Export_BAO_Export::getComponents(); + return $components[$this->getEntity()]; } /** diff --git a/CRM/Export/Form/Select.php b/CRM/Export/Form/Select.php index b151e766ac..04ac33617a 100644 --- a/CRM/Export/Form/Select.php +++ b/CRM/Export/Form/Select.php @@ -79,7 +79,7 @@ class CRM_Export_Form_Select extends CRM_Core_Form_Task { $this->_componentClause = NULL; // we need to determine component export - $components = ['Contact', 'Contribute', 'Member', 'Event', 'Pledge', 'Case', 'Grant', 'Activity']; + $components = CRM_Export_BAO_Export::getComponents(); // FIXME: This should use a modified version of CRM_Contact_Form_Search::getModeValue but it doesn't have all the contexts // FIXME: Or better still, use CRM_Core_DAO_AllCoreTables::getBriefName($daoName) to get the $entityShortName @@ -120,8 +120,8 @@ class CRM_Export_Form_Select extends CRM_Core_Form_Task { break; default: - $entityShortname = $entityDAOName = $this->getComponentName(); - break; + $entityShortname = $this->getComponentName(); + $entityDAOName = $this->controller->get('entity') ?? $entityShortname; } if (in_array($entityShortname, $components)) { @@ -496,10 +496,11 @@ FROM {$this->_componentTable} * @return array */ protected function getComponentName(): string { + // CRM_Export_Controller_Standalone has this method if (method_exists($this->controller, 'getComponent')) { return $this->controller->getComponent(); } - // This code is thought to be unreachable. + // For others, just guess based on the name of the controller $formName = CRM_Utils_System::getClassName($this->controller->getStateMachine()); $componentName = explode('_', $formName); return $componentName[1]; -- 2.25.1