}
/**
- * Get resources for one or more modules.
+ * Get resources for one or more modules, applying any changesets.
+ *
+ * NOTE: The output of this function is a little quirky; depending on the type of resource requested,
+ * the results will either be a non-associative array (for path and url-type resources)
+ * or an array indexed by moduleName (for pass-thru resources like settingsFactory, requires, permissions, bundles).
+ *
+ * Note: ChangeSets will be applied
+ * @see \CRM_Utils_Hook::alterAngular()
*
* @param string|array $moduleNames
* List of module names.
* @param string $refType
* Type of reference to the resource ('cacheUrl', 'rawUrl', 'path', 'settings').
* @return array
- * List of URLs or paths.
+ * Indexed or non-associative array, depending on resource requested (see note)
* @throws \CRM_Core_Exception
*/
public function getResources($moduleNames, $resType, $refType) {
$result = [];
- $moduleNames = (array) $moduleNames;
- foreach ($moduleNames as $moduleName) {
+ // Properties that do not require interpolation - they are added to the output keyed by moduleName
+ $passThru = ['settings', 'settingsFactory', 'requires', 'permissions', 'bundles'];
+
+ foreach ((array) $moduleNames as $moduleName) {
$module = $this->getModule($moduleName);
- if (isset($module[$resType])) {
+ if (isset($module[$resType]) && in_array($resType, $passThru, TRUE)) {
+ $result[$moduleName] = $module[$resType];
+ }
+ elseif (isset($module[$resType])) {
foreach ($module[$resType] as $file) {
$refTypeSuffix = '';
if (is_string($file) && preg_match(';^(assetBuilder|ext)://;', $file)) {
$result[] = $this->res->getUrl(parse_url($file, PHP_URL_HOST), ltrim(parse_url($file, PHP_URL_PATH), '/'), TRUE);
break;
- case 'settings':
- case 'settingsFactory':
- case 'requires':
- case 'permissions':
- case 'bundles':
- if (!empty($module[$resType])) {
- $result[$moduleName] = $module[$resType];
- }
- break;
-
default:
throw new \CRM_Core_Exception("Unrecognized resource format");
}
namespace Civi\Angular\Page;
+use Civi\Angular\Manager;
+
/**
* This page aggregates data from Angular modules.
*
* @param \Civi\Angular\Manager $angular
* @return array
*/
- public function getMetadata($moduleNames, $angular) {
- $modules = $angular->getModules();
+ public function getMetadata(array $moduleNames, Manager $angular): array {
$result = [];
foreach ($moduleNames as $moduleName) {
- if (isset($modules[$moduleName])) {
- $result[$moduleName] = [];
- $result[$moduleName]['domain'] = $modules[$moduleName]['ext'];
- $result[$moduleName]['js'] = $angular->getResources($moduleName, 'js', 'rawUrl');
- $result[$moduleName]['css'] = $angular->getResources($moduleName, 'css', 'rawUrl');
- $result[$moduleName]['partials'] = $angular->getPartials($moduleName);
- $result[$moduleName]['strings'] = $angular->getTranslatedStrings($moduleName);
- }
+ $module = $angular->getModule($moduleName);
+ $result[$moduleName] = [
+ 'domain' => $module['ext'],
+ 'js' => $angular->getResources($moduleName, 'js', 'rawUrl'),
+ 'css' => $angular->getResources($moduleName, 'css', 'rawUrl'),
+ 'partials' => $angular->getPartials($moduleName),
+ 'strings' => $angular->getTranslatedStrings($moduleName),
+ ];
}
return $result;
}