Add function Core_Component::isEnabled
authorEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 18 Jan 2022 22:08:45 +0000 (11:08 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 18 Jan 2022 22:08:45 +0000 (11:08 +1300)
It always feels like there should be an easier to discover way to check if
a component is enabled ....

CRM/Activity/Tokens.php
CRM/Contribute/Form/Contribution/Main.php
CRM/Contribute/Form/ContributionPage.php
CRM/Core/Component.php

index 40b896e814070e4d7d04a0de875f69dedf54d2a2..697a98f0d6e587f014d0941b8ffd511c8ce4f045 100644 (file)
@@ -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' => [
index b2734ff205a5da1ee062f5f256681f405049787b..fada03f546cb567e638df21c651ddf38cb634ab6 100644 (file)
@@ -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;
index 7cffe46965915748b09bc5de8771709c4618f4fe..4694ee13c5330b6bb624c3b52d58e5f17c63f138 100644 (file)
@@ -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();
index ea289635544160f504c22416c078774ac524476a..6c655ae0ff8faa8cafe1dcf7c85cbebf77be27c6 100644 (file)
@@ -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);
+  }
+
 }