mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
API Add getContentCSS() / setContentCSS() to allow per-config customisation of content_css
Fixes #7873
This commit is contained in:
parent
15410cb67a
commit
3a1c813b28
docs/en/02_Developer_Guides/15_Customising_the_Admin_Interface
src/Forms/HTMLEditor
tests/php/Forms/HTMLEditor
@ -17,6 +17,13 @@ SilverStripe\Forms\HTMLEditor\TinyMCEConfig:
|
|||||||
|
|
||||||
Will load the `mysite/css/editor.css` file.
|
Will load the `mysite/css/editor.css` file.
|
||||||
|
|
||||||
|
Alternatively, you can set this on a specific `TinyMCEConfig` instance via `setContentCSS` method.
|
||||||
|
|
||||||
|
```php
|
||||||
|
$config = new TinyMCEConfig();
|
||||||
|
$config->setContentCSS([ '/mysite/client/css/editor.css' ]);
|
||||||
|
```
|
||||||
|
|
||||||
## Custom style dropdown
|
## Custom style dropdown
|
||||||
|
|
||||||
The custom style dropdown can be enabled via the `importcss` plugin bundled with admin module. ([Doc](https://www.tinymce.com/docs/plugins/importcss/))
|
The custom style dropdown can be enabled via the `importcss` plugin bundled with admin module. ([Doc](https://www.tinymce.com/docs/plugins/importcss/))
|
||||||
|
@ -20,7 +20,7 @@ use SilverStripe\Core\Injector\Injectable;
|
|||||||
*
|
*
|
||||||
* Typically global config changes should set the active config.
|
* Typically global config changes should set the active config.
|
||||||
*
|
*
|
||||||
* The defaut config class can be changed via dependency injection to replace HTMLEditorConfig.
|
* The default config class can be changed via dependency injection to replace HTMLEditorConfig.
|
||||||
*
|
*
|
||||||
* @author "Hamish Friedlander" <hamish@silverstripe.com>
|
* @author "Hamish Friedlander" <hamish@silverstripe.com>
|
||||||
*/
|
*/
|
||||||
@ -59,7 +59,7 @@ abstract class HTMLEditorConfig
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private static $user_themes = [];
|
private static $user_themes = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of the current themes set for this config
|
* List of the current themes set for this config
|
||||||
*
|
*
|
||||||
@ -103,7 +103,7 @@ abstract class HTMLEditorConfig
|
|||||||
}
|
}
|
||||||
return $config;
|
return $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the current themes, if it is not set this will fallback to config
|
* Gets the current themes, if it is not set this will fallback to config
|
||||||
* @return array
|
* @return array
|
||||||
@ -115,7 +115,7 @@ abstract class HTMLEditorConfig
|
|||||||
}
|
}
|
||||||
return Config::inst()->get(static::class, 'user_themes');
|
return Config::inst()->get(static::class, 'user_themes');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the current theme
|
* Sets the current theme
|
||||||
*
|
*
|
||||||
@ -125,7 +125,7 @@ abstract class HTMLEditorConfig
|
|||||||
{
|
{
|
||||||
static::$current_themes = $themes;
|
static::$current_themes = $themes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the currently active configuration object. Note that the existing active
|
* Set the currently active configuration object. Note that the existing active
|
||||||
* config will not be renamed to the new identifier.
|
* config will not be renamed to the new identifier.
|
||||||
|
@ -202,6 +202,13 @@ class TinyMCEConfig extends HTMLEditorConfig
|
|||||||
*/
|
*/
|
||||||
private static $editor_css = [];
|
private static $editor_css = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of content css files to use for this instance, or null to default to editor_css config.
|
||||||
|
*
|
||||||
|
* @var string[]|null
|
||||||
|
*/
|
||||||
|
protected $contentCSS = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TinyMCE JS settings
|
* TinyMCE JS settings
|
||||||
*
|
*
|
||||||
@ -621,20 +628,42 @@ class TinyMCEConfig extends HTMLEditorConfig
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get location of all editor.css files
|
* Get location of all editor.css files.
|
||||||
|
* All resource specifiers are resolved to urls.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function getEditorCSS()
|
protected function getEditorCSS()
|
||||||
{
|
{
|
||||||
$editor = array();
|
$editor = [];
|
||||||
|
$resourceLoader = ModuleResourceLoader::singleton();
|
||||||
|
foreach ($this->getContentCSS() as $contentCSS) {
|
||||||
|
$editor[] = $resourceLoader->resolveURL($contentCSS);
|
||||||
|
}
|
||||||
|
return $editor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get list of resource paths to css files.
|
||||||
|
*
|
||||||
|
* Will default to `editor_css` config, as well as any themed `editor.css` files.
|
||||||
|
* Use setContentCSS() to override.
|
||||||
|
*
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
public function getContentCSS()
|
||||||
|
{
|
||||||
|
// Prioritise instance specific content
|
||||||
|
if (isset($this->contentCSS)) {
|
||||||
|
return $this->contentCSS;
|
||||||
|
}
|
||||||
|
|
||||||
// Add standard editor.css
|
// Add standard editor.css
|
||||||
|
$editor = [];
|
||||||
$editorCSSFiles = $this->config()->get('editor_css');
|
$editorCSSFiles = $this->config()->get('editor_css');
|
||||||
$resourceLoader = ModuleResourceLoader::singleton();
|
|
||||||
if ($editorCSSFiles) {
|
if ($editorCSSFiles) {
|
||||||
foreach ($editorCSSFiles as $editorCSS) {
|
foreach ($editorCSSFiles as $editorCSS) {
|
||||||
$editor[] = $resourceLoader->resolveURL($editorCSS);
|
$editor[] = $editorCSS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -642,12 +671,27 @@ class TinyMCEConfig extends HTMLEditorConfig
|
|||||||
$themes = HTMLEditorConfig::getThemes() ?: SSViewer::get_themes();
|
$themes = HTMLEditorConfig::getThemes() ?: SSViewer::get_themes();
|
||||||
$themedEditor = ThemeResourceLoader::inst()->findThemedCSS('editor', $themes);
|
$themedEditor = ThemeResourceLoader::inst()->findThemedCSS('editor', $themes);
|
||||||
if ($themedEditor) {
|
if ($themedEditor) {
|
||||||
$editor[] = $resourceLoader->resolveURL($themedEditor);
|
$editor[] = $themedEditor;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $editor;
|
return $editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set explicit set of CSS resources to use for `content_css` option.
|
||||||
|
*
|
||||||
|
* Note: If merging with default paths, you should call getContentCSS() and merge
|
||||||
|
* prior to assignment.
|
||||||
|
*
|
||||||
|
* @param string[] $css Array of resource paths. Supports module prefix,
|
||||||
|
* e.g. `silverstripe/admin:client/dist/styles/editor.css`
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setContentCSS($css)
|
||||||
|
{
|
||||||
|
$this->contentCSS = $css;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate gzipped TinyMCE configuration including plugins and languages.
|
* Generate gzipped TinyMCE configuration including plugins and languages.
|
||||||
* This ends up "pre-loading" TinyMCE bundled with the required plugins
|
* This ends up "pre-loading" TinyMCE bundled with the required plugins
|
||||||
|
@ -37,4 +37,28 @@ class TinyMCEConfigTest extends SapphireTest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetContentCSS()
|
||||||
|
{
|
||||||
|
TinyMCEConfig::config()->set('editor_css', [
|
||||||
|
'silverstripe/framework:tests/php/Forms/HTMLEditor.css'
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Test default config
|
||||||
|
$config = new TinyMCEConfig();
|
||||||
|
$this->assertContains('silverstripe/framework:tests/php/Forms/HTMLEditor.css', $config->getContentCSS());
|
||||||
|
|
||||||
|
// Test manual disable
|
||||||
|
$config->setContentCSS([]);
|
||||||
|
$this->assertEmpty($config->getContentCSS());
|
||||||
|
|
||||||
|
// Test replacement config
|
||||||
|
$config->setContentCSS([
|
||||||
|
'silverstripe/framework:tests/php/Forms/HTMLEditor_another.css'
|
||||||
|
]);
|
||||||
|
$this->assertEquals(
|
||||||
|
[ 'silverstripe/framework:tests/php/Forms/HTMLEditor_another.css'],
|
||||||
|
$config->getContentCSS()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user