CRM_Core_Resources - Fix loading with alternate packages path
authorTim Otten <totten@civicrm.org>
Wed, 15 Jan 2020 22:37:27 +0000 (14:37 -0800)
committerTim Otten <totten@civicrm.org>
Tue, 28 Jan 2020 22:52:07 +0000 (14:52 -0800)
CRM/Core/Resources.php

index 2c4f211c431e715d1cb074915c6fe3322d9d1bb0..99448dd0da1531e18d10a9d30cd9062f08a782c9 100644 (file)
@@ -818,6 +818,19 @@ class CRM_Core_Resources {
     // Allow hooks to modify this list
     CRM_Utils_Hook::coreResourceList($items, $region);
 
+    // Oof, existing listeners would expect $items to typically begin with 'bower_components/' or 'packages/'
+    // (using an implicit base of `[civicrm.root]`). We preserve the hook contract and cleanup $items post-hook.
+    $map = [
+      'bower_components' => rtrim(Civi::paths()->getUrl('[civicrm.bower]/.', 'absolute'), '/'),
+      'packages' => rtrim(Civi::paths()->getUrl('[civicrm.packages]/.', 'absolute'), '/'),
+    ];
+    $filter = function($m) use ($map) {
+      return $map[$m[1]] . $m[2];
+    };
+    $items = array_map(function($item) use ($filter) {
+      return is_array($item) ? $item : preg_replace_callback(';^(bower_components|packages)(/.*);', $filter, $item);
+    }, $items);
+
     return $items;
   }