I discovered this when trying to add a CSS file to load in the TinyMCE HTMLEditorField and discovered that it's a core code issue. Not sure if it's as designed or unintentional.
I'm trying to add a CSS file to the WYSIWYG editor. This file lives at <root>/mymodule/css/editor.css (I've broken up various areas of logic into submodules sibling to app). After running composer vendor-expose to expose the CSS file in resources and flushing the cache, when I load a ModelAdmin record editor view, the WYSIWYG field shows a red toast message "Failed to load content css: my module:css/editor.css."
I have discovered that this is a broader shortcoming. According to https://docs.silverstripe.org/en/4/changelogs/4.0.0/#module-paths, I should be able to use a module-only identifier (example from link ModuleLoader::getModule('mysite')->getResource('css/styles.css')->getRelativePath();). ModuleLoader::getModule() works with vendor + module and module-only prefixes. However, the loading of the editor_css values in TinyMCEConfig::getEditorCSS(), as well as css() and javascript() from the Requirements class goes through ModuleResourceLoader::resolveResource() in their codepaths, which has the following regex in the code path to match the resource: https://github.com/silverstripe/silverstripe-framework/blob/4/src/Core/Manifest/ModuleResourceLoader.php#L99
Manually running my CSS file reference against that regex does not successfully match (run on PHP CLI):
This seems like inconsistent behavior among module and resource loading, not to mention makes it difficult to use custom CSS and JS in custom module folders. A simple tweak to the regex enables it to match and load resources with module-only identifiers like the one I posted toward the top.
Affected Version
SS 4.2.1
Description
I discovered this when trying to add a CSS file to load in the TinyMCE
HTMLEditorField
and discovered that it's a core code issue. Not sure if it's as designed or unintentional.Given the following YAML config file:
I'm trying to add a CSS file to the WYSIWYG editor. This file lives at
<root>/mymodule/css/editor.css
(I've broken up various areas of logic into submodules sibling toapp
). After runningcomposer vendor-expose
to expose the CSS file inresources
and flushing the cache, when I load aModelAdmin
record editor view, the WYSIWYG field shows a red toast message "Failed to load content css: my module:css/editor.css."I have discovered that this is a broader shortcoming. According to https://docs.silverstripe.org/en/4/changelogs/4.0.0/#module-paths, I should be able to use a module-only identifier (example from link
ModuleLoader::getModule('mysite')->getResource('css/styles.css')->getRelativePath();
).ModuleLoader::getModule()
works with vendor + module and module-only prefixes. However, the loading of theeditor_css
values inTinyMCEConfig::getEditorCSS()
, as well ascss()
andjavascript()
from theRequirements
class goes throughModuleResourceLoader::resolveResource()
in their codepaths, which has the following regex in the code path to match the resource: https://github.com/silverstripe/silverstripe-framework/blob/4/src/Core/Manifest/ModuleResourceLoader.php#L99Manually running my CSS file reference against that regex does not successfully match (run on PHP CLI):
This seems like inconsistent behavior among module and resource loading, not to mention makes it difficult to use custom CSS and JS in custom module folders. A simple tweak to the regex enables it to match and load resources with module-only identifiers like the one I posted toward the top.