Managed - Move component managed entity declarations to component extensions
authorcolemanw <coleman@civicrm.org>
Fri, 1 Sep 2023 20:08:27 +0000 (16:08 -0400)
committercolemanw <coleman@civicrm.org>
Sat, 2 Sep 2023 15:50:47 +0000 (11:50 -0400)
CRM_Core_Component_Info had a quasi-listener for adding managed entities; it was only used by CiviCase.
This moves it to a real listener in the civi_case extension.

CRM/Case/Info.php
CRM/Core/Component/Info.php
CRM/Core/ManagedEntities.php
ext/civi_case/civi_case.php

index 5269af7a2d05d62ec260cf48912411438ba92dc5..bd4037ceff6ce13e9c7b8c3fe42742cb7a61c7cc 100644 (file)
@@ -51,20 +51,6 @@ class CRM_Case_Info extends CRM_Core_Component_Info {
     return $result;
   }
 
-  /**
-   * @inheritDoc
-   * @return array
-   * @throws CRM_Core_Exception
-   */
-  public function getManagedEntities() {
-    $entities = array_merge(
-      CRM_Case_ManagedEntities::createManagedCaseTypes(),
-      CRM_Case_ManagedEntities::createManagedActivityTypes(CRM_Case_XMLRepository::singleton(), CRM_Core_ManagedEntities::singleton()),
-      CRM_Case_ManagedEntities::createManagedRelationshipTypes(CRM_Case_XMLRepository::singleton(), CRM_Core_ManagedEntities::singleton())
-    );
-    return $entities;
-  }
-
   /**
    * @inheritDoc
    * @param bool $getAllUnconditionally
index 640f3e26d290e562418dbc48b5d05312e6658ba3..037b3cea0eb3e395acf3863edea59186309a5925 100644 (file)
@@ -139,17 +139,6 @@ abstract class CRM_Core_Component_Info {
    */
   abstract public function getInfo();
 
-  /**
-   * Get a list of entities to register via API.
-   *
-   * @return array
-   *   list of entities; same format as CRM_Utils_Hook::managedEntities(&$entities)
-   * @see CRM_Utils_Hook::managedEntities
-   */
-  public function getManagedEntities() {
-    return [];
-  }
-
   /**
    * Provides permissions that are unwise for Anonymous Roles to have.
    *
index 52e8d1c0c4b9c5b8a2c7cc9ee0e6fbdaf92ccc9c..dc67cfdb2107c90c2c9b3b9214dffaca831ae148 100644 (file)
@@ -523,12 +523,6 @@ class CRM_Core_ManagedEntities {
    */
   protected function getDeclarations($modules = NULL): array {
     $declarations = [];
-    // Exclude components if given a module name.
-    if (!$modules || $modules === ['civicrm']) {
-      foreach (CRM_Core_Component::getEnabledComponents() as $component) {
-        $declarations = array_merge($declarations, $component->getManagedEntities());
-      }
-    }
     CRM_Utils_Hook::managed($declarations, $modules);
     $this->validate($declarations);
     foreach (array_keys($declarations) as $name) {
index 444ef886e7dd2381ad6a596079265ef96352446b..82665f72e333d0451bd820c4b11132d9c47b73a6 100644 (file)
@@ -1,3 +1,16 @@
 <?php
 
 require_once 'civi_case.civix.php';
+use CRM_Case_ExtensionUtil as E;
+
+/**
+ * Implements hook_civicrm_managed().
+ */
+function civi_case_civicrm_managed(&$entities, $modules) {
+  // Don't optimize for $modules because the below functions delegate to other extensions
+  $entities = array_merge($entities,
+    CRM_Case_ManagedEntities::createManagedCaseTypes(),
+    CRM_Case_ManagedEntities::createManagedActivityTypes(CRM_Case_XMLRepository::singleton(), CRM_Core_ManagedEntities::singleton()),
+    CRM_Case_ManagedEntities::createManagedRelationshipTypes(CRM_Case_XMLRepository::singleton(), CRM_Core_ManagedEntities::singleton())
+  );
+}