From 166a1708df7dda05a694b1201e01496f79d386cd Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 19 Jan 2022 11:08:45 +1300 Subject: [PATCH] Add function Core_Component::isEnabled It always feels like there should be an easier to discover way to check if a component is enabled .... --- CRM/Activity/Tokens.php | 2 +- CRM/Contribute/Form/Contribution/Main.php | 2 +- CRM/Contribute/Form/ContributionPage.php | 2 +- CRM/Core/Component.php | 13 +++++++++++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CRM/Activity/Tokens.php b/CRM/Activity/Tokens.php index 40b896e814..697a98f0d6 100644 --- a/CRM/Activity/Tokens.php +++ b/CRM/Activity/Tokens.php @@ -100,7 +100,7 @@ class CRM_Activity_Tokens extends CRM_Core_EntityTokens { */ protected function getBespokeTokens(): array { $tokens = []; - if (array_key_exists('CiviCase', CRM_Core_Component::getEnabledComponents())) { + if (CRM_Core_Component::isEnabled('CiviCase')) { $tokens['case_id'] = ts('Activity Case ID'); return [ 'case_id' => [ diff --git a/CRM/Contribute/Form/Contribution/Main.php b/CRM/Contribute/Form/Contribution/Main.php index b2734ff205..fada03f546 100644 --- a/CRM/Contribute/Form/Contribution/Main.php +++ b/CRM/Contribute/Form/Contribution/Main.php @@ -372,7 +372,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu //don't build membership block when pledge_id is passed if (empty($this->_values['pledge_id']) && empty($this->_ccid)) { $this->_separateMembershipPayment = FALSE; - if (in_array('CiviMember', $config->enableComponents)) { + if (CRM_Core_Component::isEnabled('CiviMember')) { $isTest = 0; if ($this->_action & CRM_Core_Action::PREVIEW) { $isTest = 1; diff --git a/CRM/Contribute/Form/ContributionPage.php b/CRM/Contribute/Form/ContributionPage.php index 7cffe46965..4694ee13c5 100644 --- a/CRM/Contribute/Form/ContributionPage.php +++ b/CRM/Contribute/Form/ContributionPage.php @@ -142,7 +142,7 @@ class CRM_Contribute_Form_ContributionPage extends CRM_Core_Form { // Preload libraries required by the "Profiles" tab $schemas = ['IndividualModel', 'OrganizationModel', 'ContributionModel']; - if (in_array('CiviMember', CRM_Core_Config::singleton()->enableComponents)) { + if (CRM_Core_Component::isEnabled('CiviMember')) { $schemas[] = 'MembershipModel'; } CRM_UF_Page_ProfileEditor::registerProfileScripts(); diff --git a/CRM/Core/Component.php b/CRM/Core/Component.php index ea28963554..6c655ae0ff 100644 --- a/CRM/Core/Component.php +++ b/CRM/Core/Component.php @@ -423,4 +423,17 @@ class CRM_Core_Component { return $components; } + /** + * Is the specified component enabled. + * + * @param string $component + * Component name - ie CiviMember, CiviContribute, CiviEvent... + * + * @return bool + * Is the component enabled. + */ + public static function isEnabled(string $component): bool { + return in_array($component, CRM_Core_Config::singleton()->enableComponents, TRUE); + } + } -- 2.25.1