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:
Sam Minnee 2016-09-15 11:33:51 +12:00
parent 6b847d3614
commit cebcf7fb8c

View File

@ -95,19 +95,42 @@ 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 {