From 90c62ad31e77e23a652cdd98736e0d5a8e09bad2 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 12 Dec 2019 15:33:07 -0800 Subject: [PATCH] hook_angularModules - Accept 'partialsCallback' for dynamic partials This is similar to the antecedent commit which used a field 'snippets' that contained a list of HTML files and their content. However, this uses a callback function instead of providing the full HTML content. This makes it safer to work with the Angular metadata without needing to load the content of all partials into memory. --- CRM/Utils/Hook.php | 4 ++++ Civi/Angular/Manager.php | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CRM/Utils/Hook.php b/CRM/Utils/Hook.php index 656238fc12..89dd2be19d 100644 --- a/CRM/Utils/Hook.php +++ b/CRM/Utils/Hook.php @@ -2244,6 +2244,10 @@ abstract class CRM_Utils_Hook { * - js: array, list of JS files or globs. * - css: array, list of CSS files or globs. * - partials: array, list of base-dirs containing HTML. + * - partialsCallback: mixed, a callback function which generates a list of HTML + * function(string $moduleName, array $moduleDefn) => array(string $file => string $html) + * For future-proofing, use a serializable callback (e.g. string/array). + * See also: Civi\Core\Resolver. * - requires: array, list of required Angular modules. * - basePages: array, uncondtionally load this module onto the given Angular pages. [v4.7.21+] * If omitted, default to "array('civicrm/a')" for backward compat. diff --git a/Civi/Angular/Manager.php b/Civi/Angular/Manager.php index 8c759b0ee0..e5f169a385 100644 --- a/Civi/Angular/Manager.php +++ b/Civi/Angular/Manager.php @@ -226,7 +226,9 @@ class Manager { */ public function getRawPartials($name) { $module = $this->getModule($name); - $result = $module['snippets'] ?? []; + $result = !empty($module['partialsCallback']) + ? \Civi\Core\Resolver::singleton()->call($module['partialsCallback'], [$name, $module]) + : []; if (isset($module['partials'])) { foreach ($module['partials'] as $partialDir) { $partialDir = $this->res->getPath($module['ext']) . '/' . $partialDir; -- 2.25.1