mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
NEW: More flexible theme resolution for framework and cms.
using ‘silverstripe/framework’ or ‘silverstripe/cms’ will resolve the right path even if these folders are in the project root. ‘vendor/module:/sub/path’ theme references are also supported so that the admin sub-theme can be accessed.
This commit is contained in:
parent
6b847d3614
commit
cebcf7fb8c
@ -95,20 +95,43 @@ class ThemeResourceLoader {
|
|||||||
// <module> is always the name of the install directory, not necessarily the composer name.
|
// <module> is always the name of the install directory, not necessarily the composer name.
|
||||||
$parts = explode(':', $identifier, 2);
|
$parts = explode(':', $identifier, 2);
|
||||||
|
|
||||||
list($vendor, $module) = explode('/', $parts[0], 2);
|
if(count($parts) > 1) {
|
||||||
$theme = count($parts) > 1 ? $parts[1] : '';
|
$theme = $parts[1];
|
||||||
|
// "module/vendor:/sub/path"
|
||||||
|
if($theme[0] === '/') {
|
||||||
|
$subpath = $theme;
|
||||||
|
|
||||||
$path = $module . ($theme ? '/themes/'.$theme : '');
|
// "module/vendor:subtheme"
|
||||||
|
} else {
|
||||||
|
$subpath = '/themes/' . $theme;
|
||||||
|
}
|
||||||
|
|
||||||
// Right now we require $module to be a silverstripe module (in root) or theme (in themes dir)
|
// "module/vendor"
|
||||||
// If both exist, we prefer theme
|
} else {
|
||||||
if (is_dir(THEMES_PATH . '/' .$path)) {
|
$subpath = '';
|
||||||
return THEMES_DIR . '/' . $path;
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
return $path;
|
// To do: implement more flexible module path lookup
|
||||||
|
$package = $parts[0];
|
||||||
|
switch($package) {
|
||||||
|
case 'silverstripe/framework':
|
||||||
|
$modulePath = FRAMEWORK_DIR;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'silverstripe/cms':
|
||||||
|
$modulePath = CMS_DIR;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
list($vendor, $modulePath) = explode('/', $parts[0], 2);
|
||||||
|
// If the module is in the themes/<module>/ prefer that
|
||||||
|
if (is_dir(THEMES_PATH . '/' .$modulePath)) {
|
||||||
|
$modulePath = THEMES_DIR . '/' . $$modulePath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ltrim($modulePath . $subpath, '/');
|
||||||
|
}
|
||||||
// Otherwise it's a (deprecated) old-style "theme" identifier
|
// Otherwise it's a (deprecated) old-style "theme" identifier
|
||||||
else {
|
else {
|
||||||
return THEMES_DIR.'/'.$identifier;
|
return THEMES_DIR.'/'.$identifier;
|
||||||
|
Loading…
Reference in New Issue
Block a user