diff --git a/CRM/Activity/BAO/Query.php b/CRM/Activity/BAO/Query.php index 3aa0f6acad70..a7eee549e7a8 100644 --- a/CRM/Activity/BAO/Query.php +++ b/CRM/Activity/BAO/Query.php @@ -499,7 +499,7 @@ public static function buildSearchForm(&$form) { // Add engagement level CRM-7775. $buildEngagementLevel = FALSE; $buildSurveyResult = FALSE; - if (CRM_Campaign_BAO_Campaign::isCampaignEnable() && + if (CRM_Campaign_BAO_Campaign::isComponentEnabled() && CRM_Campaign_BAO_Campaign::accessCampaign() ) { $buildEngagementLevel = TRUE; diff --git a/CRM/Activity/Form/Activity.php b/CRM/Activity/Form/Activity.php index e334ca203b79..ce069e8be431 100644 --- a/CRM/Activity/Form/Activity.php +++ b/CRM/Activity/Form/Activity.php @@ -682,7 +682,7 @@ public function buildQuickForm() { // Add engagement level CRM-7775 $buildEngagementLevel = FALSE; - if (CRM_Campaign_BAO_Campaign::isCampaignEnable() && + if (CRM_Campaign_BAO_Campaign::isComponentEnabled() && CRM_Campaign_BAO_Campaign::accessCampaign() ) { $buildEngagementLevel = TRUE; @@ -697,7 +697,7 @@ public function buildQuickForm() { // check for survey activity $this->_isSurveyActivity = FALSE; - if ($this->_activityId && CRM_Campaign_BAO_Campaign::isCampaignEnable() && + if ($this->_activityId && CRM_Campaign_BAO_Campaign::isComponentEnabled() && CRM_Campaign_BAO_Campaign::accessCampaign() ) { diff --git a/CRM/Campaign/BAO/Campaign.php b/CRM/Campaign/BAO/Campaign.php index 0174f2c5e319..2314942c10c7 100644 --- a/CRM/Campaign/BAO/Campaign.php +++ b/CRM/Campaign/BAO/Campaign.php @@ -255,7 +255,7 @@ public static function getPermissionedCampaigns( //do check for component. if ($doCheckForComponent) { - $campaigns['isCampaignEnabled'] = $isValid = self::isCampaignEnable(); + $campaigns['isCampaignEnabled'] = $isValid = self::isComponentEnabled(); } //do check for permissions. @@ -283,11 +283,12 @@ public static function getPermissionedCampaigns( /** * Is CiviCampaign enabled. - * + * @deprecated * @return bool */ public static function isCampaignEnable(): bool { - return CRM_Core_Component::isEnabled('CiviCampaign'); + CRM_Core_Error::deprecatedFunctionWarning('isComponentEnabled'); + return self::isComponentEnabled(); } /** diff --git a/CRM/Case/BAO/Case.php b/CRM/Case/BAO/Case.php index 4ec0524892ec..ae7ba35fb001 100644 --- a/CRM/Case/BAO/Case.php +++ b/CRM/Case/BAO/Case.php @@ -30,11 +30,12 @@ class CRM_Case_BAO_Case extends CRM_Case_DAO_Case implements \Civi\Core\HookInte /** * Is CiviCase enabled? - * + * @deprecated * @return bool */ public static function enabled() { - return CRM_Core_Component::isEnabled('CiviCase'); + CRM_Core_Error::deprecatedFunctionWarning('isComponentEnabled'); + return self::isComponentEnabled(); } /** @@ -63,7 +64,7 @@ public static function add(&$params) { */ public static function on_hook_civicrm_post(\Civi\Core\Event\PostEvent $e): void { // FIXME: The EventScanner ought to skip over disabled components when registering HookInterface - if (!CRM_Core_Component::isEnabled('CiviCase')) { + if (!self::isComponentEnabled()) { return; } if ($e->entity === 'Activity' && in_array($e->action, ['create', 'edit'])) { @@ -2467,7 +2468,7 @@ public static function checkPermission($activityId, $operation, $actTypeId = NUL } //do check for civicase component enabled. - if ($checkComponent && !self::enabled()) { + if ($checkComponent && !self::isComponentEnabled()) { return $allow; } @@ -2709,7 +2710,7 @@ public static function checkPermission($activityId, $operation, $actTypeId = NUL * or 'access all cases and activities' */ public static function accessCiviCase() { - if (!self::enabled()) { + if (!self::isComponentEnabled()) { return FALSE; } @@ -2732,7 +2733,7 @@ public static function accessCiviCase() { * @return bool */ public static function accessCase($caseId, $denyClosed = TRUE) { - if (!$caseId || !self::enabled()) { + if (!$caseId || !self::isComponentEnabled()) { return FALSE; } diff --git a/CRM/Core/BAO/UFGroup.php b/CRM/Core/BAO/UFGroup.php index d3fc94a74b32..bd55d33c1a45 100644 --- a/CRM/Core/BAO/UFGroup.php +++ b/CRM/Core/BAO/UFGroup.php @@ -2164,7 +2164,7 @@ public static function buildProfile( $form->add('textarea', $name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName)); } elseif (substr($fieldName, -11) == 'campaign_id') { - if (CRM_Campaign_BAO_Campaign::isCampaignEnable()) { + if (CRM_Campaign_BAO_Campaign::isComponentEnabled()) { $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(CRM_Utils_Array::value($contactId, $form->_componentCampaigns )); diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index a18728ae04f3..8321d64385c3 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -3364,4 +3364,14 @@ private function makeNameFromLabel(): void { $this->name = $name . $suffix; } + /** + * Check if component is enabled for this DAO class + * + * @return bool + */ + public static function isComponentEnabled(): bool { + $daoName = static::class; + return !defined("$daoName::COMPONENT") || CRM_Core_Component::isEnabled($daoName::COMPONENT); + } + } diff --git a/CRM/Core/EntityTokens.php b/CRM/Core/EntityTokens.php index 098b1e1ed6ca..b33ae4ebe3ba 100644 --- a/CRM/Core/EntityTokens.php +++ b/CRM/Core/EntityTokens.php @@ -409,7 +409,7 @@ protected function getSkippedFields(): array { // 'not a real field' offered up by case - seems like an oddity // we should skip at the top level for now. $fields = ['tags']; - if (!CRM_Campaign_BAO_Campaign::isCampaignEnable()) { + if (!CRM_Campaign_BAO_Campaign::isComponentEnabled()) { $fields[] = 'campaign_id'; } return $fields; diff --git a/CRM/Core/Resources.php b/CRM/Core/Resources.php index 88a8d64a0ecc..27c13416ca2f 100644 --- a/CRM/Core/Resources.php +++ b/CRM/Core/Resources.php @@ -504,7 +504,7 @@ protected static function getEntityRefMetadata() { foreach (CRM_Core_DAO_AllCoreTables::daoToClass() as $entity => $daoName) { // Skip DAOs of disabled components - if (defined("$daoName::COMPONENT") && !CRM_Core_Component::isEnabled($daoName::COMPONENT)) { + if (!$daoName::isComponentEnabled()) { continue; } $baoName = str_replace('_DAO_', '_BAO_', $daoName); diff --git a/CRM/Mailing/Selector/Browse.php b/CRM/Mailing/Selector/Browse.php index 8151febab94e..df1442be6ff7 100644 --- a/CRM/Mailing/Selector/Browse.php +++ b/CRM/Mailing/Selector/Browse.php @@ -162,7 +162,7 @@ public function &getColumnHeaders($action = NULL, $output = NULL) { ] ); - if (CRM_Campaign_BAO_Campaign::isCampaignEnable()) { + if (CRM_Campaign_BAO_Campaign::isComponentEnabled()) { self::$_columnHeaders[] = [ 'name' => ts('Campaign'), 'sort' => 'campaign_id', diff --git a/CRM/Utils/Check/Component/Case.php b/CRM/Utils/Check/Component/Case.php index 89f623ed73fa..d6b4c1148824 100644 --- a/CRM/Utils/Check/Component/Case.php +++ b/CRM/Utils/Check/Component/Case.php @@ -40,7 +40,7 @@ public function __construct() { * @inheritDoc */ public function isEnabled() { - return CRM_Case_BAO_Case::enabled(); + return CRM_Case_BAO_Case::isComponentEnabled(); } /** diff --git a/Civi/API/Request.php b/Civi/API/Request.php index 55765a9bcb36..62cd7605cdf6 100644 --- a/Civi/API/Request.php +++ b/Civi/API/Request.php @@ -52,7 +52,7 @@ public static function create(string $entity, string $action, array $params) { } // Check enabled components $daoName = \CRM_Core_DAO_AllCoreTables::getFullName($entity); - if ($daoName && defined("{$daoName}::COMPONENT") && !\CRM_Core_Component::isEnabled($daoName::COMPONENT)) { + if ($daoName && !$daoName::isComponentEnabled()) { throw new \Civi\API\Exception\NotImplementedException("$entity API is not available because " . $daoName::COMPONENT . " component is disabled"); } $args = (array) CoreUtil::getInfoItem($entity, 'class_args'); diff --git a/Civi/Api4/Action/Entity/Get.php b/Civi/Api4/Action/Entity/Get.php index 13b96573fe63..a7fa82d76217 100644 --- a/Civi/Api4/Action/Entity/Get.php +++ b/Civi/Api4/Action/Entity/Get.php @@ -35,7 +35,7 @@ protected function getRecords() { return array_filter($provider->getEntities(), function($entity) { // Only include DAO entities from enabled components $daoName = $entity['dao'] ?? NULL; - return (!$daoName || !defined("{$daoName}::COMPONENT") || \CRM_Core_Component::isEnabled($daoName::COMPONENT)); + return (!$daoName || $daoName::isComponentEnabled()); }); } diff --git a/templates/CRM/Activity/Form/ActivityView.tpl b/templates/CRM/Activity/Form/ActivityView.tpl index b0a02df612d4..35c0297cfe5c 100644 --- a/templates/CRM/Activity/Form/ActivityView.tpl +++ b/templates/CRM/Activity/Form/ActivityView.tpl @@ -36,7 +36,7 @@ {/if} {if $values.engagement_level AND - call_user_func( array( 'CRM_Campaign_BAO_Campaign', 'isCampaignEnable' ) )} + call_user_func( array( 'CRM_Campaign_BAO_Campaign', 'isComponentEnabled' ) )} {ts}Engagement Level{/ts}{$values.engagement_level} {/if} diff --git a/templates/CRM/Contribute/Page/ContributionPage.tpl b/templates/CRM/Contribute/Page/ContributionPage.tpl index 2321d2524b2b..330b87da8fab 100644 --- a/templates/CRM/Contribute/Page/ContributionPage.tpl +++ b/templates/CRM/Contribute/Page/ContributionPage.tpl @@ -37,7 +37,7 @@ {ts}Title{/ts} {ts}ID{/ts} {ts}Enabled?{/ts} - {if call_user_func(array('CRM_Campaign_BAO_Campaign','isCampaignEnable'))} + {if call_user_func(array('CRM_Campaign_BAO_Campaign','isComponentEnabled'))} {ts}Campaign{/ts} {/if} @@ -48,7 +48,7 @@ {$row.title} {$row.id} {if $row.is_active eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if} - {if call_user_func(array('CRM_Campaign_BAO_Campaign','isCampaignEnable'))} + {if call_user_func(array('CRM_Campaign_BAO_Campaign','isComponentEnabled'))} {$row.campaign} {/if} diff --git a/templates/CRM/Event/Page/ManageEvent.tpl b/templates/CRM/Event/Page/ManageEvent.tpl index b634902a124c..c69aa9943f32 100644 --- a/templates/CRM/Event/Page/ManageEvent.tpl +++ b/templates/CRM/Event/Page/ManageEvent.tpl @@ -41,7 +41,7 @@ {ts}Public?{/ts} {ts}Starts{/ts} {ts}Ends{/ts} - {if call_user_func(array('CRM_Campaign_BAO_Campaign','isCampaignEnable'))} + {if call_user_func(array('CRM_Campaign_BAO_Campaign','isComponentEnabled'))} {ts}Campaign{/ts} {/if} {ts}Active?{/ts} @@ -64,7 +64,7 @@ {if $row.is_public eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if} {$row.start_date|crmDate:"%b %d, %Y %l:%M %P"} {$row.end_date|crmDate:"%b %d, %Y %l:%M %P"} - {if call_user_func(array('CRM_Campaign_BAO_Campaign','isCampaignEnable'))} + {if call_user_func(array('CRM_Campaign_BAO_Campaign','isComponentEnabled'))} {$row.campaign} {/if} diff --git a/templates/CRM/Mailing/Page/Browse.tpl b/templates/CRM/Mailing/Page/Browse.tpl index c0fdd64d5a36..01482f230bda 100644 --- a/templates/CRM/Mailing/Page/Browse.tpl +++ b/templates/CRM/Mailing/Page/Browse.tpl @@ -67,7 +67,7 @@ {$row.scheduled} {$row.start} {$row.end} - {if call_user_func(array('CRM_Campaign_BAO_Campaign','isCampaignEnable'))} + {if call_user_func(array('CRM_Campaign_BAO_Campaign','isComponentEnabled'))} {$row.campaign} {/if} {$row.action|smarty:nodefaults|replace:'xx':$row.id}