.../Plugin/ckeditor/plugin/StylesCombo.php | 21 ++++++++++++++++++-- .../ckeditor/Tests/CKEditorPluginManagerTest.php | 10 +++++----- .../lib/Drupal/ckeditor/Tests/CKEditorTest.php | 4 ++-- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/ckeditor/plugin/StylesCombo.php b/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/ckeditor/plugin/StylesCombo.php index 9f09a11..2b2b1b8 100644 --- a/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/ckeditor/plugin/StylesCombo.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/ckeditor/plugin/StylesCombo.php @@ -9,6 +9,7 @@ use Drupal\ckeditor\CKEditorPluginBase; use Drupal\ckeditor\CKEditorPluginConfigurableInterface; +use Drupal\ckeditor\CKEditorPluginContextualInterface; use Drupal\Component\Utility\NestedArray; use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; @@ -23,7 +24,7 @@ * module = "ckeditor" * ) */ -class StylesCombo extends CKEditorPluginBase implements CKEditorPluginConfigurableInterface { +class StylesCombo extends CKEditorPluginBase implements CKEditorPluginConfigurableInterface, CKEditorPluginContextualInterface { /** * Implements \Drupal\ckeditor\Plugin\CKEditorPluginInterface::isInternal(). @@ -41,17 +42,33 @@ public function getFile() { } /** + * Implements \Drupal\ckeditor\Plugin\CKEditorPluginContextualInterface::isEnabled(). + */ + public function isEnabled(Editor $editor) { + // The StylesCombo plugin is always "enabled": + // - when the "Styles" button is not enabled, we set stylesSet = false, to + // prevent CKEditor from loading styles.js + // - otherwise, we configure stylesSet according to the user's settings. + return TRUE; + } + + /** * Implements \Drupal\ckeditor\Plugin\CKEditorPluginInterface::getConfig(). */ public function getConfig(Editor $editor) { $config = array(); - // Next, add the stylesSet setting, if its button is enabled. + // Add the stylesSet setting. $toolbar_buttons = array_unique(NestedArray::mergeDeepArray($editor->settings['toolbar']['buttons'])); if (in_array('Styles', $toolbar_buttons)) { $styles = $editor->settings['plugins']['stylescombo']['styles']; $config['stylesSet'] = $this->generateStylesSetSetting($styles); } + // If the "Styles" button is disabled, then we set it to FALSE, to prevent + // CKEditor from loading the default styles.js at all. + else { + $config['stylesSet'] = FALSE; + } return $config; } diff --git a/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorPluginManagerTest.php b/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorPluginManagerTest.php index 32fe534..7a945e2 100644 --- a/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorPluginManagerTest.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorPluginManagerTest.php @@ -71,7 +71,7 @@ function testEnabledPlugins() { sort($definitions); $this->assertIdentical(array('internal', 'stylescombo'), $definitions, 'No CKEditor plugins found besides the built-in ones.'); $this->assertIdentical(array(), $this->manager->getEnabledPluginFiles($editor), 'Only built-in plugins are enabled.'); - $this->assertIdentical(array('internal' => NULL), $this->manager->getEnabledPluginFiles($editor, TRUE), 'Only the "internal" plugin is enabled.'); + $this->assertIdentical(array('stylescombo' => NULL, 'internal' => NULL), $this->manager->getEnabledPluginFiles($editor, TRUE), 'Only the "internal" and "stylescombo" plugins are enabled.'); // Enable the CKEditor Test module, which has the Llama plugin (plus three // variations of it, to cover all possible ways a plugin can be enabled) and @@ -85,7 +85,7 @@ function testEnabledPlugins() { sort($plugin_ids); $this->assertIdentical(array('internal', 'llama', 'llama_button', 'llama_contextual', 'llama_contextual_and_button', 'stylescombo'), $plugin_ids, 'Additional CKEditor plugins found.'); $this->assertIdentical(array(), $this->manager->getEnabledPluginFiles($editor), 'Only the internal plugins are enabled.'); - $this->assertIdentical(array('internal' => NULL), $this->manager->getEnabledPluginFiles($editor, TRUE), 'Only the "internal" plugin is enabled.'); +$this->assertIdentical(array('stylescombo' => NULL, 'internal' => NULL), $this->manager->getEnabledPluginFiles($editor, TRUE), 'Only the "internal" and "stylescombo" plugins are enabled.'); // Case 3: enable each of the newly available plugins, if possible: // a. Llama: cannot be enabled, since it does not implement @@ -109,18 +109,18 @@ function testEnabledPlugins() { $file['cb'] = 'core/modules/ckeditor/tests/modules/js/llama_contextual_and_button.js'; $expected = array('llama_button' => $file['b'], 'llama_contextual_and_button' => $file['cb']); $this->assertIdentical($expected, $this->manager->getEnabledPluginFiles($editor), 'The LlamaButton and LlamaContextualAndButton plugins are enabled.'); - $this->assertIdentical(array('internal' => NULL) + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LlamaButton and LlamaContextualAndButton plugins are enabled.'); + $this->assertIdentical(array('internal' => NULL, 'stylescombo' => NULL) + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LlamaButton and LlamaContextualAndButton plugins are enabled.'); $editor->settings['toolbar']['buttons'][0] = $original_toolbar; $editor->settings['toolbar']['buttons'][0][] = 'Strike'; $editor->save(); $expected = array('llama_contextual' => $file['c'], 'llama_contextual_and_button' => $file['cb']); $this->assertIdentical($expected, $this->manager->getEnabledPluginFiles($editor), 'The LLamaContextual and LlamaContextualAndButton plugins are enabled.'); - $this->assertIdentical(array('internal' => NULL) + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LlamaContextual and LlamaContextualAndButton plugins are enabled.'); + $this->assertIdentical(array('internal' => NULL, 'stylescombo' => NULL) + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LlamaContextual and LlamaContextualAndButton plugins are enabled.'); $editor->settings['toolbar']['buttons'][0][] = 'Llama'; $editor->save(); $expected = array('llama_button' => $file['b'], 'llama_contextual' => $file['c'], 'llama_contextual_and_button' => $file['cb']); $this->assertIdentical($expected, $this->manager->getEnabledPluginFiles($editor), 'The LlamaButton, LlamaContextual and LlamaContextualAndButton plugins are enabled.'); - $this->assertIdentical(array('internal' => NULL) + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LLamaButton, LlamaContextual and LlamaContextualAndButton plugins are enabled.'); + $this->assertIdentical(array('stylescombo' => NULL, 'internal' => NULL) + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LLamaButton, LlamaContextual and LlamaContextualAndButton plugins are enabled.'); } } diff --git a/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php b/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php index b3a3d9c..f51fd85 100644 --- a/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php @@ -78,7 +78,7 @@ function testGetJSSettings() { $editor = entity_load('editor', 'filtered_html'); // Default toolbar. - $expected_config = $this->getDefaultInternalConfig() + array( + $expected_config = $this->getDefaultStylesComboConfig()+ $this->getDefaultInternalConfig() + array( 'allowedContent' => $this->getDefaultAllowedContentConfig(), 'toolbar' => $this->getDefaultToolbarConfig(), 'contentsCss' => $this->getDefaultContentsCssConfig(), @@ -247,7 +247,7 @@ protected function getDefaultInternalConfig() { } protected function getDefaultStylesComboConfig() { - return array(); + return array('stylesSet' => FALSE); } protected function getDefaultAllowedContentConfig() {