From: Tim Otten Date: Tue, 17 Sep 2013 07:21:58 +0000 (-0700) Subject: CRM-13410 - CiviCase - Automatically register/unregister case-types defined via hook_... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=6b982e013fbbb4e67a033f0657c10ae68197458e;p=civicrm-core.git CRM-13410 - CiviCase - Automatically register/unregister case-types defined via hook_civicrm_caseTypes ---------------------------------------- * CRM-13410: Allow extensions to define case-types http://issues.civicrm.org/jira/browse/CRM-13410 --- diff --git a/CRM/Case/Info.php b/CRM/Case/Info.php index cefcbab5d3..c9183e5f63 100644 --- a/CRM/Case/Info.php +++ b/CRM/Case/Info.php @@ -52,6 +52,51 @@ class CRM_Case_Info extends CRM_Core_Component_Info { ); } + // docs inherited from interface + public function getManagedEntities() { + // Use hook_civicrm_caseTypes to build a list of OptionValues + // In the long run, we may want more specialized logic for this, but + // this design is fairly convenient and will allow us to replace it + // without changing the hook_civicrm_caseTypes interface. + $entities = array(); + + $caseTypes = array(); + CRM_Utils_Hook::caseTypes($caseTypes); + + $proc = new CRM_Case_XMLProcessor(); + $caseTypesGroupId = civicrm_api3('OptionGroup', 'getvalue', array('name' => 'case_type', 'return' => 'id')); + if (!is_numeric($caseTypesGroupId)) { + throw new CRM_Core_Exception("Found invalid ID for OptionGroup (case_type)"); + } + foreach ($caseTypes as $name => $caseType) { + $xml = $proc->retrieve($name); + if (!$xml) { + throw new CRM_Core_Exception("Failed to load XML for case type (" . $name . ")"); + } + + if (isset($caseType['module'], $caseType['name'], $caseType['file'])) { + $entities[] = array( + 'module' => $caseType['module'], + 'name' => $caseType['name'], + 'entity' => 'OptionValue', + 'params' => array( + 'version' => 3, + 'name' => $caseType['name'], + 'label' => (string) $xml->name, + 'description' => (string) $xml->description, // CRM_Utils_Array::value('description', $caseType, ''), + 'option_group_id' => $caseTypesGroupId, + 'is_reserved' => 1, + ), + ); + } + else { + throw new CRM_Core_Exception("Invalid case type"); + } + } + + return $entities; + } + // docs inherited from interface public function getPermissions($getAllUnconditionally = FALSE) { return array(