Fix references to resource paths / urls

This commit is contained in:
Damian Mooyman 2017-10-10 16:51:47 +13:00
parent 5d6a10ca58
commit 6a55dcfc16
No known key found for this signature in database
GPG Key ID: 78B823A10DE27D1A
4 changed files with 22 additions and 11 deletions

View File

@ -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);
}
/**

View File

@ -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)

View File

@ -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() . '/';

View File

@ -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);