CRM-13410 - Allow "Components" to define managed-entities
authorTim Otten <totten@civicrm.org>
Tue, 17 Sep 2013 07:21:28 +0000 (00:21 -0700)
committerTim Otten <totten@civicrm.org>
Tue, 17 Sep 2013 07:24:13 +0000 (00:24 -0700)
----------------------------------------
* CRM-13410: Allow extensions to define case-types
  http://issues.civicrm.org/jira/browse/CRM-13410

CRM/Core/Component/Info.php
CRM/Core/ManagedEntities.php

index ef6a8dd5afcbf4af1053bfabb9be776d6249d855..2913bc3d729394b7de877542bedc42c4d9ea25a3 100644 (file)
@@ -126,6 +126,16 @@ 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 array();
+  }
+
   /**
    * Provides permissions that are used by component.
    * Needs to be implemented in component's information
index a1b08c8fa45895f7e64724426ddfda76bbfbd0b5..1c0c5655552f911e74767e0d716a59b4bd47fc0b 100644 (file)
@@ -23,6 +23,9 @@ class CRM_Core_ManagedEntities {
     static $singleton;
     if ($fresh || !$singleton) {
       $declarations = array();
+      foreach (CRM_Core_Component::getEnabledComponents() as $component) {
+        $declarations = array_merge($declarations, $component->getManagedEntities());
+      }
       CRM_Utils_Hook::managed($declarations);
       $singleton = new CRM_Core_ManagedEntities(CRM_Core_Module::getAll(), $declarations);
     }
@@ -99,7 +102,7 @@ class CRM_Core_ManagedEntities {
     $dao->module = $module->name;
     $dao->find();
     while ($dao->fetch()) {
-      if ($todos[$dao->name]) {
+      if (isset($todos[$dao->name]) && $todos[$dao->name]) {
         // update existing entity; remove from $todos
         $defaults = array('id' => $dao->entity_id, 'is_active' => 1); // FIXME: test whether is_active is valid
         $params = array_merge($defaults, $todos[$dao->name]['params']);