Skip to content
Snippets Groups Projects
Commit 1a7b176d authored by Tim van Dijen's avatar Tim van Dijen Committed by Jaime Pérez Crespo
Browse files

Make assets-filter usable for modules (#1209)

parent 10a58513
No related branches found
No related tags found
No related merge requests found
...@@ -165,16 +165,25 @@ class Template extends Response ...@@ -165,16 +165,25 @@ class Template extends Response
/** /**
* Return the URL of an asset, including a cache-buster parameter that depends on the last modification time of * Return the URL of an asset, including a cache-buster parameter that depends on the last modification time of
* the original file. * the original file.
*
* @param string $asset * @param string $asset
* @param string|null $module
* @return string * @return string
*/ */
public function asset($asset) public function asset($asset, $module = null)
{ {
$file = $this->configuration->getBaseDir().'www/assets/'.$asset; $baseDir = $this->configuration->getBaseDir();
$basePath = $this->configuration->getBasePath();
if (is_null($module)) {
$file = $baseDir.'www/assets/'.$asset;
$path = $basePath.'assets/'.$asset;
} else {
$file = $baseDir.'modules/'.$module.'/www/assets/'.$asset;
$path = $basePath.'module.php/'.$module.'/assets/'.$asset;
}
if (!file_exists($file)) { if (!file_exists($file)) {
// don't be too harsh if an asset is missing, just pretend it's there... // don't be too harsh if an asset is missing, just pretend it's there...
return $this->configuration->getBasePath().'assets/'.$asset; return $basePath.'assets/'.$asset;
} }
$tag = $this->configuration->getVersion(); $tag = $this->configuration->getVersion();
...@@ -182,7 +191,8 @@ class Template extends Response ...@@ -182,7 +191,8 @@ class Template extends Response
$tag = strval(filemtime($file)); $tag = strval(filemtime($file));
} }
$tag = substr(hash('md5', $tag), 0, 5); $tag = substr(hash('md5', $tag), 0, 5);
return $this->configuration->getBasePath().'assets/'.$asset.'?tag='.$tag;
return $path.'?tag='.$tag;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment