From 6a55dcfc16eacf3210fa8d630953d588433275d5 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Tue, 10 Oct 2017 16:51:47 +1300 Subject: [PATCH] Fix references to resource paths / urls --- src/Core/Manifest/ModuleResourceLoader.php | 20 +++++++++++++++---- src/Security/CMSSecurity.php | 5 ++--- src/View/Requirements_Backend.php | 2 ++ .../Forms/HTMLEditor/HTMLEditorFieldTest.php | 6 ++---- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/Core/Manifest/ModuleResourceLoader.php b/src/Core/Manifest/ModuleResourceLoader.php index 2996649c2..aa5b8dd8a 100644 --- a/src/Core/Manifest/ModuleResourceLoader.php +++ b/src/Core/Manifest/ModuleResourceLoader.php @@ -4,6 +4,7 @@ namespace SilverStripe\Core\Manifest; use InvalidArgumentException; use SilverStripe\Core\Injector\Injectable; +use SilverStripe\Core\Injector\Injector; use SilverStripe\View\TemplateGlobalProvider; /** @@ -22,6 +23,10 @@ class ModuleResourceLoader implements TemplateGlobalProvider */ public function resolvePath($resource) { + // Skip blank resources + if (empty($resource)) { + return null; + } $resourceObj = $this->resolveResource($resource); if ($resourceObj instanceof ModuleResource) { return $resourceObj->getRelativePath(); @@ -37,11 +42,18 @@ class ModuleResourceLoader implements TemplateGlobalProvider */ public function resolveURL($resource) { - $resourceObj = $this->resolveResource($resource); - if ($resourceObj instanceof ModuleResource) { - return $resourceObj->getURL(); + // Skip blank resources + if (empty($resource)) { + return null; } - return $resource; + + // Resolve resource to reference + $resource = $this->resolveResource($resource); + + // Resolve resource to url + /** @var ResourceURLGenerator $generator */ + $generator = Injector::inst()->get(ResourceURLGenerator::class); + return $generator->urlForResource($resource); } /** diff --git a/src/Security/CMSSecurity.php b/src/Security/CMSSecurity.php index b40010546..9aa9e262b 100644 --- a/src/Security/CMSSecurity.php +++ b/src/Security/CMSSecurity.php @@ -40,9 +40,8 @@ class CMSSecurity extends Security SSViewer::set_themes(LeftAndMain::config()->uninherited('admin_themes')); // Core styles / vendor scripts - $admin = ModuleLoader::getModule('silverstripe/admin'); - Requirements::javascript($admin->getRelativeResourcePath('client/dist/js/vendor.js')); - Requirements::css($admin->getRelativeResourcePath('client/dist/styles/bundle.css')); + Requirements::javascript('silverstripe/admin: client/dist/js/vendor.js'); + Requirements::css('silverstripe/admin: client/dist/styles/bundle.css'); } public function login($request = null, $service = Authenticator::CMS_LOGIN) diff --git a/src/View/Requirements_Backend.php b/src/View/Requirements_Backend.php index 0411f02cf..abee657b8 100644 --- a/src/View/Requirements_Backend.php +++ b/src/View/Requirements_Backend.php @@ -989,6 +989,8 @@ class Requirements_Backend */ public function add_i18n_javascript($langDir, $return = false) { + $langDir = ModuleResourceLoader::singleton()->resolvePath($langDir); + $files = array(); $base = Director::baseFolder() . '/'; diff --git a/tests/php/Forms/HTMLEditor/HTMLEditorFieldTest.php b/tests/php/Forms/HTMLEditor/HTMLEditorFieldTest.php index 7030601bc..13737dc4e 100644 --- a/tests/php/Forms/HTMLEditor/HTMLEditorFieldTest.php +++ b/tests/php/Forms/HTMLEditor/HTMLEditorFieldTest.php @@ -11,6 +11,7 @@ use SilverStripe\Assets\Tests\Storage\AssetStoreTest\TestAssetStore; use SilverStripe\Core\Config\Config; use SilverStripe\Core\Manifest\ModuleLoader; use SilverStripe\Core\Manifest\ModuleManifest; +use SilverStripe\Core\Manifest\ModuleResourceLoader; use SilverStripe\Dev\CSSContentParser; use SilverStripe\Dev\FunctionalTest; use SilverStripe\Forms\HTMLEditor\HTMLEditorField; @@ -68,12 +69,9 @@ class HTMLEditorFieldTest extends FunctionalTest public function testCasting() { // Shim TinyMCE so silverstripe/admin doesn't have to be installed - $framework = ModuleLoader::getModule('silverstripe/framework'); TinyMCEConfig::config()->set( 'base_dir', - $framework->getRelativeResourcePath( - 'tests/php/Forms/HTMLEditor/TinyMCECombinedGeneratorTest/tinymce' - ) + 'silverstripe/framework: tests/php/Forms/HTMLEditor/TinyMCECombinedGeneratorTest/tinymce' ); HtmlEditorField::config()->set('use_gzip', false);