From 6b86870e8143334a5a36c2c6640541bdf7f1081c Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 17 Sep 2013 00:20:48 -0700 Subject: [PATCH] CRM-13410 - CiviCase - Load XML files from extensions (as defined with hook_civicrm_caseTypes) ---------------------------------------- * CRM-13410: Allow extensions to define case-types http://issues.civicrm.org/jira/browse/CRM-13410 --- CRM/Case/XMLProcessor.php | 24 +++++++++++++++++++++--- CRM/Utils/Hook.php | 10 ++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/CRM/Case/XMLProcessor.php b/CRM/Case/XMLProcessor.php index c22f4e8aa7..eecedd51d6 100644 --- a/CRM/Case/XMLProcessor.php +++ b/CRM/Case/XMLProcessor.php @@ -36,10 +36,10 @@ class CRM_Case_XMLProcessor { static protected $_xml; + static protected $_hookCache = NULL; + function retrieve($caseType) { - // trim all spaces from $caseType - $caseType = str_replace('_', ' ', $caseType); - $caseType = CRM_Utils_String::munge(ucwords($caseType), '', 0); + $caseType = self::mungeCaseType($caseType); if (!CRM_Utils_Array::value($caseType, self::$_xml)) { if (!self::$_xml) { @@ -87,6 +87,17 @@ class CRM_Case_XMLProcessor { ) ); } + + if (!file_exists($fileName)) { + if (self::$_hookCache === NULL) { + self::$_hookCache = array(); + CRM_Utils_Hook::caseTypes(self::$_hookCache); + } + if (isset(self::$_hookCache[$caseType], self::$_hookCache[$caseType]['file'])) { + $fileName = self::$_hookCache[$caseType]['file']; + } + } + if (!file_exists($fileName)) { return FALSE; } @@ -101,6 +112,13 @@ class CRM_Case_XMLProcessor { return self::$_xml[$caseType]; } + public static function mungeCaseType($caseType) { + // trim all spaces from $caseType + $caseType = str_replace('_', ' ', $caseType); + $caseType = CRM_Utils_String::munge(ucwords($caseType), '', 0); + return $caseType; + } + function &allActivityTypes($indexName = TRUE, $all = FALSE) { static $activityTypes = NULL; if (!$activityTypes) { diff --git a/CRM/Utils/Hook.php b/CRM/Utils/Hook.php index 198664f0d7..cd38ec7253 100644 --- a/CRM/Utils/Hook.php +++ b/CRM/Utils/Hook.php @@ -748,6 +748,16 @@ abstract class CRM_Utils_Hook { ); } + /** + * This hook is called when locating CiviCase types. + * + * @param array $caseTypes + * @return void + */ + static function caseTypes(&$caseTypes) { + return self::singleton()->invoke(1, $caseTypes, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_caseTypes'); + } + /** * This hook is called soon after the CRM_Core_Config object has ben initialized. * You can use this hook to modify the config object and hence behavior of CiviCRM dynamically. -- 2.25.1