.../lib/Drupal/ckeditor/CKEditorPluginManager.php | 13 +++++---- .../Plugin/ckeditor/plugin/StylesCombo.php | 29 ++------------------ .../ckeditor/Plugin/editor/editor/CKEditor.php | 16 +++++++---- .../ckeditor/Tests/CKEditorPluginManagerTest.php | 20 +++++++------- .../lib/Drupal/ckeditor/Tests/CKEditorTest.php | 11 ++------ 5 files changed, 33 insertions(+), 56 deletions(-) diff --git a/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginManager.php b/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginManager.php index 11fe690..5500241 100644 --- a/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginManager.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginManager.php @@ -35,7 +35,7 @@ public function __construct(array $namespaces) { } /** - * Retrieves enabled plugins' files, keyed by plugin ID. + * Determines which plug-ins are enabled. * * For CKEditor plugins that implement: * - CKEditorPluginButtonsInterface, not CKEditorPluginContextualInterface, @@ -59,7 +59,7 @@ public function __construct(array $namespaces) { * the Drupal root-relative plugin files as values. * For internal plugins, the value is NULL. */ - public function getEnabledPluginFiles(Editor $editor, $include_internal_plugins = FALSE) { + public function getEnabledPlugins(Editor $editor, $include_internal_plugins = FALSE) { $plugins = array_keys($this->getDefinitions()); $toolbar_buttons = array_unique(NestedArray::mergeDeepArray($editor->settings['toolbar']['buttons'])); $enabled_plugins = array(); @@ -92,17 +92,18 @@ public function getEnabledPluginFiles(Editor $editor, $include_internal_plugins } /** - * Retrieves all available CKEditor buttons, keyed by plugin ID. + * Retrieves all plugins that implement CKEditorPluginButtonsInterface. * * @param \Drupal\editor\Plugin\Core\Entity\Editor $editor * A configured text editor object. * @return array - * All availble CKEditor buttons, with plugin IDs as keys and button - * metadata (as implemented by getButtons()) as values. + * A list of the CKEditor plugins that implement buttons, with the plugin + * IDs as keys and lists of button metadata (as implemented by getButtons()) + * as values. * * @see CKEditorPluginButtonsInterface::getButtons() */ - public function getButtons(Editor $editor) { + public function getButtonsPlugins(Editor $editor) { $plugins = array_keys($this->getDefinitions()); $buttons_plugins = array(); 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 2c07758..a787676 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,7 +9,6 @@ use Drupal\ckeditor\CKEditorPluginBase; use Drupal\ckeditor\CKEditorPluginConfigurableInterface; -use Drupal\ckeditor\CKEditorPluginContextualInterface; use Drupal\Component\Utility\NestedArray; use Drupal\Component\Annotation\Plugin; use Drupal\Core\Annotation\Translation; @@ -24,7 +23,7 @@ * module = "ckeditor" * ) */ -class StylesCombo extends CKEditorPluginBase implements CKEditorPluginConfigurableInterface, CKEditorPluginContextualInterface { +class StylesCombo extends CKEditorPluginBase implements CKEditorPluginConfigurableInterface { /** * Implements \Drupal\ckeditor\Plugin\CKEditorPluginInterface::isInternal(). @@ -42,34 +41,12 @@ 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(); - - // 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; - } - + $styles = $editor->settings['plugins']['stylescombo']['styles']; + $config['stylesSet'] = $this->generateStylesSetSetting($styles); return $config; } diff --git a/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/editor/editor/CKEditor.php b/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/editor/editor/CKEditor.php index 5956a9b..57b857d 100644 --- a/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/editor/editor/CKEditor.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/editor/editor/CKEditor.php @@ -58,7 +58,7 @@ public function settingsForm(array $form, array &$form_state, Editor $editor) { array( 'type' => 'setting', 'data' => array('ckeditor' => array( - 'toolbarAdmin' => theme('ckeditor_settings_toolbar', array('editor' => $editor, 'plugins' => $manager->getButtons($editor))), + 'toolbarAdmin' => theme('ckeditor_settings_toolbar', array('editor' => $editor, 'plugins' => $manager->getButtonsPlugins($editor))), )), ) ), @@ -112,24 +112,30 @@ public function getJSSettings(Editor $editor) { $manager = drupal_container()->get('plugin.manager.ckeditor.plugin'); // Get the settings for all enabled plugins, even the internal ones. - $enabled_plugins = array_keys($manager->getEnabledPluginFiles($editor, TRUE)); + $enabled_plugins = array_keys($manager->getEnabledPlugins($editor, TRUE)); foreach ($enabled_plugins as $plugin_id) { $plugin = $manager->createInstance($plugin_id); $settings += $plugin->getConfig($editor); } // Next, set the most fundamental CKEditor settings. - $external_plugin_files = $manager->getEnabledPluginFiles($editor); + $external_plugins = $manager->getEnabledPlugins($editor); $settings += array( 'toolbar' => $this->buildToolbarJSSetting($editor), 'contentsCss' => $this->buildContentsCssJSSetting($editor), - 'extraPlugins' => implode(',', array_keys($external_plugin_files)), + 'extraPlugins' => implode(',', array_keys($external_plugins)), 'language' => $language_interface->langcode, + // Configure CKEditor to not load styles.js. The StylesCombo plugin will + // set stylesSet according to the user's settings, if the "Styles" button + // is enabled. We cannot get rid of this until CKEditor will stop loading + // styles.js by default. + // See http://dev.ckeditor.com/ticket/9992#comment:9. + 'stylesSet' => FALSE, ); // Finally, set Drupal-specific CKEditor settings. $settings += array( - 'drupalExternalPlugins' => array_map('file_create_url', $external_plugin_files), + 'drupalExternalPlugins' => array_map('file_create_url', $external_plugins), ); return $settings; diff --git a/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorPluginManagerTest.php b/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorPluginManagerTest.php index 7a945e2..b7383d7 100644 --- a/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorPluginManagerTest.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorPluginManagerTest.php @@ -70,8 +70,8 @@ function testEnabledPlugins() { $definitions = array_keys($this->manager->getDefinitions()); 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('stylescombo' => NULL, 'internal' => NULL), $this->manager->getEnabledPluginFiles($editor, TRUE), 'Only the "internal" and "stylescombo" plugins are enabled.'); + $this->assertIdentical(array(), $this->manager->getEnabledPlugins($editor), 'Only built-in plugins are enabled.'); + $this->assertIdentical(array('internal' => NULL), $this->manager->getEnabledPlugins($editor, TRUE), 'Only the "internal" plugin is 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 @@ -84,8 +84,8 @@ function testEnabledPlugins() { $plugin_ids = array_keys($this->manager->getDefinitions()); 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('stylescombo' => NULL, 'internal' => NULL), $this->manager->getEnabledPluginFiles($editor, TRUE), 'Only the "internal" and "stylescombo" plugins are enabled.'); + $this->assertIdentical(array(), $this->manager->getEnabledPlugins($editor), 'Only the internal plugins are enabled.'); + $this->assertIdentical(array('internal' => NULL), $this->manager->getEnabledPlugins($editor, TRUE), 'Only the "internal" plugin is enabled.'); // Case 3: enable each of the newly available plugins, if possible: // a. Llama: cannot be enabled, since it does not implement @@ -108,19 +108,19 @@ function testEnabledPlugins() { $file['c'] = 'core/modules/ckeditor/tests/modules/js/llama_contextual.js'; $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, 'stylescombo' => NULL) + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LlamaButton and LlamaContextualAndButton plugins are enabled.'); + $this->assertIdentical($expected, $this->manager->getEnabledPlugins($editor), 'The LlamaButton and LlamaContextualAndButton plugins are enabled.'); + $this->assertIdentical(array('internal' => NULL) + $expected, $this->manager->getEnabledPlugins($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, 'stylescombo' => NULL) + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LlamaContextual and LlamaContextualAndButton plugins are enabled.'); + $this->assertIdentical($expected, $this->manager->getEnabledPlugins($editor), 'The LLamaContextual and LlamaContextualAndButton plugins are enabled.'); + $this->assertIdentical(array('internal' => NULL) + $expected, $this->manager->getEnabledPlugins($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('stylescombo' => NULL, 'internal' => NULL) + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LLamaButton, LlamaContextual and LlamaContextualAndButton plugins are enabled.'); + $this->assertIdentical($expected, $this->manager->getEnabledPlugins($editor), 'The LlamaButton, LlamaContextual and LlamaContextualAndButton plugins are enabled.'); + $this->assertIdentical(array('internal' => NULL) + $expected, $this->manager->getEnabledPlugins($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 5bbd5a2..db4dbec 100644 --- a/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php @@ -75,11 +75,12 @@ function testGetJSSettings() { $editor = entity_load('editor', 'filtered_html'); // Default toolbar. - $expected_config = $this->getDefaultStylesComboConfig()+ $this->getDefaultInternalConfig() + array( + $expected_config = $this->getDefaultInternalConfig() + array( 'toolbar' => $this->getDefaultToolbarConfig(), 'contentsCss' => $this->getDefaultContentsCssConfig(), 'extraPlugins' => '', 'language' => 'en', + 'stylesSet' => FALSE, 'drupalExternalPlugins' => array(), ); $this->assertIdentical($expected_config, $this->ckeditor->getJSSettings($editor), 'Generated JS settings are correct for default configuration.'); @@ -181,10 +182,6 @@ function testStylesComboGetConfig() { $manager = drupal_container()->get('plugin.manager.ckeditor.plugin'); $stylescombo_plugin = $manager->createInstance('stylescombo'); - // Default toolbar. - $expected = $this->getDefaultStylesComboConfig(); - $this->assertIdentical($expected, $stylescombo_plugin->getConfig($editor), '"StylesCombo" plugin configuration built correctly for default toolbar.'); - // Styles dropdown/button enabled: new setting should be present. $editor->settings['toolbar']['buttons'][0][] = 'Styles'; $editor->settings['plugins']['stylescombo']['styles'] = ''; @@ -233,10 +230,6 @@ protected function getDefaultInternalConfig() { ); } - protected function getDefaultStylesComboConfig() { - return array('stylesSet' => FALSE); - } - protected function getDefaultToolbarConfig() { return array( 0 => array('items' => array('Bold', 'Italic')),