From cebcf7fb8c4bedb45cf8360978e95c11a831ff8b Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Thu, 15 Sep 2016 11:33:51 +1200 Subject: [PATCH] NEW: More flexible theme resolution for framework and cms. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- View/ThemeResourceLoader.php | 41 ++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/View/ThemeResourceLoader.php b/View/ThemeResourceLoader.php index 5ae2bb56a..1f33e1070 100644 --- a/View/ThemeResourceLoader.php +++ b/View/ThemeResourceLoader.php @@ -95,19 +95,42 @@ class ThemeResourceLoader { // is always the name of the install directory, not necessarily the composer name. $parts = explode(':', $identifier, 2); - list($vendor, $module) = explode('/', $parts[0], 2); - $theme = count($parts) > 1 ? $parts[1] : ''; + if(count($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) - // If both exist, we prefer theme - if (is_dir(THEMES_PATH . '/' .$path)) { - return THEMES_DIR . '/' . $path; + // "module/vendor" + } else { + $subpath = ''; } - 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// 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 else {