diff --git a/modules/system/classes/CombineAssets.php b/modules/system/classes/CombineAssets.php index 7d6ef36be..23b41f61e 100644 --- a/modules/system/classes/CombineAssets.php +++ b/modules/system/classes/CombineAssets.php @@ -404,7 +404,7 @@ class CombineAssets $filesSalt = null; foreach ($assets as $asset) { $filters = $this->getFilters(File::extension($asset)) ?: []; - $path = File::symbolizePath($asset, null) ?: $this->localPath . $asset; + $path = file_exists($asset) ? $asset : File::symbolizePath($asset, null) ?: $this->localPath . $asset; $files[] = new FileAsset($path, $filters, public_path()); $filesSalt .= $this->localPath . $asset; } @@ -458,7 +458,7 @@ class CombineAssets $key = ''; $assetFiles = array_map(function ($file) { - return File::symbolizePath($file, null) ?: $this->localPath . $file; + return file_exists($file) ? $file : File::symbolizePath($file, null) ?: $this->localPath . $file; }, $assets); foreach ($assetFiles as $file) { diff --git a/modules/system/traits/AssetMaker.php b/modules/system/traits/AssetMaker.php index 4637af7a0..e81283082 100644 --- a/modules/system/traits/AssetMaker.php +++ b/modules/system/traits/AssetMaker.php @@ -4,6 +4,7 @@ use Url; use Html; use System\Models\Parameter; use System\Models\PluginVersion; +use System\Classes\CombineAssets; /** * Asset Maker Trait @@ -110,6 +111,10 @@ trait AssetMaker */ public function addJs($name, $attributes = []) { + if (is_array($name)) { + $name = $this->combineAssets($name); + } + $jsPath = $this->getAssetPath($name); if (isset($this->controller)) { @@ -136,6 +141,10 @@ trait AssetMaker */ public function addCss($name, $attributes = []) { + if (is_array($name)) { + $name = $this->combineAssets($name); + } + $cssPath = $this->getAssetPath($name); if (isset($this->controller)) { @@ -179,6 +188,22 @@ trait AssetMaker } } + /** + * Run the provided assets through the Asset Combiner + * @param array $assets Collection of assets + * @param string $localPath Prefix all assets with this path (optional) + * @return string + */ + public function combineAssets(array $assets, $localPath = '') + { + // Short circuit if no assets actually provided + if (empty($assets)) { + return ''; + } + $assetPath = !empty($localPath) ? $localPath : $this->assetPath; + return Url::to(CombineAssets::combine($assets, $assetPath)); + } + /** * Returns an array of all registered asset paths. * @return array