BUG: Fix duplicate plugins on HTML editor fields (#8559)

* BUG: Fix duplicate plugins on HTML editor fields

* Add new test
This commit is contained in:
Luke Edwards 2018-11-02 12:26:53 +13:00 committed by Aaron Carlino
parent 55f95b7bc8
commit 8866e7674a
4 changed files with 12 additions and 1 deletions

View File

@ -83,6 +83,7 @@ abstract class HTMLEditorConfig
// Create new instance if unconfigured
if (!isset(self::$configs[$identifier])) {
self::$configs[$identifier] = static::create();
self::$configs[$identifier]->setOption('editorIdentifier', $identifier);
}
return self::$configs[$identifier];
}
@ -98,6 +99,7 @@ abstract class HTMLEditorConfig
{
if ($config) {
self::$configs[$identifier] = $config;
self::$configs[$identifier]->setOption('editorIdentifier', $identifier);
} else {
unset(self::$configs[$identifier]);
}

View File

@ -130,11 +130,13 @@ class TinyMCECombinedGenerator implements TinyMCEScriptGenerator, Flushable
// Register vars for config
$baseDirJS = Convert::raw2js(Director::absoluteBaseURL());
$name = Convert::raw2js($this->checkName($config));
$buffer = [];
$buffer[] = <<<SCRIPT
(function() {
var baseTag = window.document.getElementsByTagName('base');
var baseURL = baseTag.length ? baseTag[0].baseURI : '$baseDirJS';
var editorIdentifier = '$name';
SCRIPT;
$buffer[] = <<<SCRIPT
(function() {

View File

@ -140,7 +140,7 @@ class HTMLEditorConfigTest extends SapphireTest
$this->assertNotContains('plugin1', array_keys($plugins));
$this->assertNotContains('plugin2', array_keys($plugins));
}
public function testRequireJSIncludesAllConfigs()
{
$a = HTMLEditorConfig::get('configA');

View File

@ -9,6 +9,13 @@ use SilverStripe\Forms\HTMLEditor\TinyMCEConfig;
class TinyMCEConfigTest extends SapphireTest
{
public function testEditorIdentifier()
{
$config = TinyMCEConfig::get('myconfig');
$this->assertEquals('myconfig', $config->getOption('editorIdentifier'));
}
/**
* Ensure that all TinyMCEConfig.tinymce_lang are valid
*/