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

View File

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

View File

@ -9,6 +9,13 @@ use SilverStripe\Forms\HTMLEditor\TinyMCEConfig;
class TinyMCEConfigTest extends SapphireTest 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 * Ensure that all TinyMCEConfig.tinymce_lang are valid
*/ */