core/modules/ckeditor/ckeditor.admin.inc | 135 ++++++++------------
core/modules/ckeditor/ckeditor.api.php | 7 +-
core/modules/ckeditor/ckeditor.module | 2 +-
.../ckeditor/CKEditorPluginContextualInterface.php | 2 +-
.../lib/Drupal/ckeditor/CKEditorPluginManager.php | 14 +-
.../ckeditor/Plugin/editor/editor/CKEditor.php | 20 +--
.../ckeditor/Tests/CKEditorPluginManagerTest.php | 10 +-
.../lib/Drupal/ckeditor/Tests/CKEditorTest.php | 2 +-
8 files changed, 81 insertions(+), 111 deletions(-)
diff --git a/core/modules/ckeditor/ckeditor.admin.inc b/core/modules/ckeditor/ckeditor.admin.inc
index 10f55fe..f7e414d 100644
--- a/core/modules/ckeditor/ckeditor.admin.inc
+++ b/core/modules/ckeditor/ckeditor.admin.inc
@@ -12,23 +12,21 @@
*/
function template_preprocess_ckeditor_settings_toolbar(&$variables) {
// Simplify the language direction information for toolbar buttons.
- global $language;
- $variables['language_direction'] = isset($language->direction) && $language->direction === LANGUAGE_RTL ? 'rtl' : 'ltr';
+ $language_interface = language(LANGUAGE_TYPE_INTERFACE);
+ $variables['language_direction'] = $language_interface->direction ? 'rtl' : 'ltr';
// Create lists of active and disabled buttons.
$editor = $variables['editor'];
$plugins = $variables['plugins'];
$buttons = array();
$variables['multiple_buttons'] = array();
- foreach ($plugins as $plugin) {
- if (isset($plugin['buttons'])) {
- foreach ($plugin['buttons'] as $button_name => $button) {
- if (!empty($button['multiple'])) {
- $variables['multiple_buttons'][$button_name] = $button;
- }
- $button['name'] = $button_name;
- $buttons[$button_name] = $button;
+ foreach ($plugins as $plugin => $buttons) {
+ foreach ($buttons as $button_name => $button) {
+ $button['name'] = $button_name;
+ if (!empty($button['multiple'])) {
+ $variables['multiple_buttons'][$button_name] = $button;
}
+ $buttons[$button_name] = $button;
}
}
$variables['active_buttons'] = array();
@@ -53,74 +51,64 @@ function theme_ckeditor_settings_toolbar($variables) {
$plugins = $variables['plugins'];
$rtl = $variables['language_direction'] === 'rtl' ? '_rtl' : '';
- // Assemble items to be added to active button rows.
- foreach ($variables['active_buttons'] as $row_number => $row_buttons) {
- foreach ($row_buttons as $button) {
- $button_name = $button['name'];
- if (isset($button['image_alternative'])) {
- $data = $button['image_alternative' . $rtl];
- }
- elseif (isset($button['image'])) {
- $data = theme('image', array('uri' => $button['image' . $rtl], 'title' => $button['label']));
- }
- else {
- $data = '?';
- }
- $button_item = array(
- 'data' => $data,
- 'data-button-name' => $button_name,
- );
- if (!empty($button['multiple'])) {
- $button['attributes']['class'][] = 'ckeditor-multiple-button';
- }
- if (!empty($button['attributes'])) {
- $button_item = array_merge($button_item, $button['attributes']);
- }
- $active_buttons[$row_number][] = $button_item;
- }
- }
- // Assemble list of disabled buttons (which are always a single row).
- foreach ($variables['disabled_buttons'] as $button_name => $button) {
+ $build_button_item = function($button, $rtl) {
+ // Value of the button item.
if (isset($button['image_alternative'])) {
- $data = $button['image_alternative'];
+ $value = $button['image_alternative' . $rtl];
}
elseif (isset($button['image'])) {
- $data = theme('image', array('uri' => $button['image' . $rtl], 'title' => $button['label']));
+ $value = theme('image', array('uri' => $button['image' . $rtl], 'title' => $button['label']));
}
else {
- $data = '?';
+ $value = '?';
+ }
+
+ // Set additional attribute on the button if it can occur multiple times.
+ if (!empty($button['multiple'])) {
+ $button['attributes']['class'][] = 'ckeditor-multiple-button';
}
+
+ // Build the button item.
$button_item = array(
- 'data' => $data,
- 'data-button-name' => $button_name,
+ 'value' => $value,
+ 'data-button-name' => $button['name'],
);
- if (isset($button['attributes'])) {
+ if (!empty($button['attributes'])) {
$button_item = array_merge($button_item, $button['attributes']);
}
- $disabled_buttons[] = $button_item;
+
+ return $button_item;
+ };
+
+ // Assemble items to be added to active button rows.
+ $active_buttons = array();
+ foreach ($variables['active_buttons'] as $row_number => $row_buttons) {
+ foreach ($row_buttons as $button) {
+ $active_buttons[$row_number][] = $build_button_item($button, $rtl);
+ }
+ }
+ // Assemble list of disabled buttons (which are always a single row).
+ $disabled_buttons = array();
+ foreach ($variables['disabled_buttons'] as $button) {
+ $disabled_buttons[] = $build_button_item($button, $rtl);
}
// Assemble list of multiple buttons that may be added multiple times.
+ $multiple_buttons = array();
foreach ($variables['multiple_buttons'] as $button_name => $button) {
- if (isset($button['image_alternative'])) {
- $data = $button['image_alternative'];
- }
- elseif (isset($button['image'])) {
- $data = theme('image', array('uri' => $button['image' . $rtl], 'title' => $button['label']));
- }
- else {
- $data = '?';
- }
- $button_item = array(
- 'data' => $data,
- 'data-button-name' => $button_name,
- );
- $button['attributes']['class'][] = 'ckeditor-multiple-button';
- if (isset($button['attributes'])) {
- $button_item = array_merge($button_item, $button['attributes']);
- }
- $multiple_buttons[] = $button_item;
+ $multiple_buttons[] = $build_button_item($button, $rtl);
}
+ $print_buttons = function($buttons) {
+ $output = '';
+ foreach ($buttons as $button) {
+ $value = $button['value'];
+ unset($button['value']);
+ $attributes = (string) new Attribute($button);
+ $output .= '
';
foreach ($active_buttons as $button_row) {
$output .= '
';
}
if (empty($active_buttons)) {
@@ -151,21 +134,11 @@ function theme_ckeditor_settings_toolbar($variables) {
$output .= '
' . t('Available buttons') . '';
$output .= '
';
diff --git a/core/modules/ckeditor/ckeditor.api.php b/core/modules/ckeditor/ckeditor.api.php
index c548543..0b4f343 100644
--- a/core/modules/ckeditor/ckeditor.api.php
+++ b/core/modules/ckeditor/ckeditor.api.php
@@ -34,11 +34,8 @@ function hook_ckeditor_plugin_info_alter(array &$plugins) {
* providing a CKEditor plugin. This list of CSS files is only used in the
* iframe versions of CKEditor.
*
- * Note that because this hook is only called for modules and the active theme,
- * front-end themes will not be able to use this hook to add their own CSS files
- * if a different admin theme is active. Instead, front-end themes and base
- * themes may specify CSS files to be used in iframe instances of CKEditor
- * through an entry in their .info file:
+ * Front-end themes (and base themes) can easily specify CSS files to be used in
+ * iframe instances of CKEditor through an entry in their .info file:
*
* @code
* ckeditor_stylesheets[] = css/ckeditor-iframe.css
diff --git a/core/modules/ckeditor/ckeditor.module b/core/modules/ckeditor/ckeditor.module
index 31eee04..be8c834 100644
--- a/core/modules/ckeditor/ckeditor.module
+++ b/core/modules/ckeditor/ckeditor.module
@@ -107,7 +107,7 @@ function _ckeditor_theme_css($theme = NULL) {
}
}
if (isset($info['base theme'])) {
- $css = array_merge($css, _ckeditor_theme_css($info['base theme']));
+ $css = array_merge(_ckeditor_theme_css($info['base theme'], $css));
}
}
return $css;
diff --git a/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginContextualInterface.php b/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginContextualInterface.php
index 0bb759d..b1b88df 100644
--- a/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginContextualInterface.php
+++ b/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginContextualInterface.php
@@ -12,7 +12,7 @@
/**
* Defines an interface for contextually enabled CKEditor plugins.
*
- * Contextually enabled CKEditor plugins can be enabled off an explicit setting,
+ * Contextually enabled CKEditor plugins can be enabled via an explicit setting,
* or enable themselves based on the configuration of another setting, such as
* enabling based on a particular button being present in the toolbar.
*
diff --git a/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginManager.php b/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginManager.php
index 4843e9c..57a3a4b 100644
--- a/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginManager.php
+++ b/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginManager.php
@@ -49,15 +49,15 @@ public function __construct() {
*
* @param \Drupal\editor\Plugin\Core\Entity\Editor $editor
* A configured text editor object.
- * @param bool $exclude_internal_plugins
- * Defaults to TRUE. When set to FALSE, plugins whose isInternal() method
+ * @param bool $include_internal_plugins
+ * Defaults to FALSE. When set to TRUE, plugins whose isInternal() method
* returns TRUE will also be included.
* @return array
* A list of the enabled CKEditor plugins, with the plugin IDs as keys and
* the Drupal root-relative plugin files as values.
* For internal plugins, the value is NULL.
*/
- public function getEnabledPlugins(Editor $editor, $exclude_internal_plugins = TRUE) {
+ 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();
@@ -65,7 +65,7 @@ public function getEnabledPlugins(Editor $editor, $exclude_internal_plugins = TR
foreach ($plugins as $plugin_id) {
$plugin = $this->createInstance($plugin_id);
- if ($exclude_internal_plugins && $plugin->isInternal()) {
+ if (!$include_internal_plugins && $plugin->isInternal()) {
continue;
}
@@ -103,16 +103,16 @@ public function getEnabledPlugins(Editor $editor, $exclude_internal_plugins = TR
*/
public function getButtonsPlugins(Editor $editor) {
$plugins = array_keys($this->getDefinitions());
- $configurable_plugins = array();
+ $buttons_plugins = array();
foreach ($plugins as $plugin_id) {
$plugin = $this->createInstance($plugin_id);
if ($plugin instanceof CKEditorPluginButtonsInterface) {
- $configurable_plugins[$plugin_id]['buttons'] = $plugin->getButtons();
+ $buttons_plugins[$plugin_id] = $plugin->getButtons();
}
}
- return $configurable_plugins;
+ return $buttons_plugins;
}
/**
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 2dffa09..ee7cc32 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
@@ -26,7 +26,7 @@ class CKEditor extends EditorBase {
/**
* Implements \Drupal\editor\Plugin\EditorInterface::getDefaultSettings().
*/
- function getDefaultSettings() {
+ public function getDefaultSettings() {
return array(
'toolbar' => array(
'buttons' => array(
@@ -45,7 +45,7 @@ function getDefaultSettings() {
/**
* Implements \Drupal\editor\Plugin\EditorInterface::settingsForm().
*/
- function settingsForm(array $form, array &$form_state, Editor $editor) {
+ public function settingsForm(array $form, array &$form_state, Editor $editor) {
$module_path = drupal_get_path('module', 'ckeditor');
$manager = drupal_container()->get('plugin.manager.ckeditor.plugin');
@@ -88,7 +88,7 @@ function settingsForm(array $form, array &$form_state, Editor $editor) {
/**
* Implements \Drupal\editor\Plugin\EditorInterface::settingsFormSubmit().
*/
- function settingsFormSubmit(array $form, array &$form_state) {
+ public function settingsFormSubmit(array $form, array &$form_state) {
// Modify the toolbar settings by reference. The values in
// $form_state['values']['editor']['settings'] will be saved directly by
// editor_form_filter_admin_format_submit().
@@ -105,14 +105,14 @@ function settingsFormSubmit(array $form, array &$form_state) {
/**
* Implements \Drupal\editor\Plugin\EditorInterface::getJSSettings().
*/
- function getJSSettings(Editor $editor) {
- global $language;
+ public function getJSSettings(Editor $editor) {
+ $language_interface = language(LANGUAGE_TYPE_INTERFACE);
$settings = array();
$manager = drupal_container()->get('plugin.manager.ckeditor.plugin');
// Get the settings for all enabled plugins, even the internal ones.
- $enabled_plugins = array_keys($manager->getEnabledPlugins($editor, FALSE));
+ $enabled_plugins = array_keys($manager->getEnabledPlugins($editor, TRUE));
foreach ($enabled_plugins as $plugin_id) {
$plugin = $manager->createInstance($plugin_id);
$settings += $plugin->getConfig($editor);
@@ -124,7 +124,7 @@ function getJSSettings(Editor $editor) {
'toolbar' => $this->buildToolbarJSSetting($editor),
'contentsCss' => $this->buildContentsCssJSSetting($editor),
'extraPlugins' => implode(',', array_keys($external_plugins)),
- 'language' => isset($language->language) ? $language->language : '',
+ 'language' => $language_interface->langcode,
);
// Finally, set Drupal-specific CKEditor settings.
@@ -138,7 +138,7 @@ function getJSSettings(Editor $editor) {
/**
* Implements \Drupal\editor\Plugin\EditorInterface::getLibraries().
*/
- function getLibraries(Editor $editor) {
+ public function getLibraries(Editor $editor) {
return array(
array('ckeditor', 'drupal.ckeditor'),
);
@@ -154,7 +154,7 @@ function getLibraries(Editor $editor) {
* @return array
* An array containing the "toolbar" configuration.
*/
- function buildToolbarJSSetting(Editor $editor) {
+ public function buildToolbarJSSetting(Editor $editor) {
$toolbar = array();
foreach ($editor->settings['toolbar']['buttons'] as $row_number => $row) {
$button_group = array();
@@ -185,7 +185,7 @@ function buildToolbarJSSetting(Editor $editor) {
* @return array
* An array containing the "contentsCss" configuration.
*/
- function buildContentsCssJSSetting(Editor $editor) {
+ public function buildContentsCssJSSetting(Editor $editor) {
$css = array(
drupal_get_path('module', 'ckeditor') . '/css/ckeditor.css',
drupal_get_path('module', 'ckeditor') . '/css/ckeditor-iframe.css',
diff --git a/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorPluginManagerTest.php b/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorPluginManagerTest.php
index 9a7d1fe..4eb5524 100644
--- a/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorPluginManagerTest.php
+++ b/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorPluginManagerTest.php
@@ -69,7 +69,7 @@ function testEnabledPlugins() {
// Case 1: no CKEditor plugins.
$this->assertIdentical(array('internal'), array_keys($this->manager->getDefinitions()), 'No CKEditor plugins found besides the built-in ones.');
$this->assertIdentical(array(), $this->manager->getEnabledPlugins($editor), 'Only the internal plugins is enabled.');
- $this->assertIdentical(array('internal' => NULL), $this->manager->getEnabledPlugins($editor, FALSE), 'Only the "internal" plugin is 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
@@ -82,7 +82,7 @@ function testEnabledPlugins() {
sort($plugin_ids);
$this->assertIdentical(array('internal', 'llama', 'llama_button', 'llama_contextual', 'llama_contextual_and_button'), $plugin_ids, 'Additional CKEditor plugins found.');
$this->assertIdentical(array(), $this->manager->getEnabledPlugins($editor), 'Only the internal plugins are enabled.');
- $this->assertIdentical(array('internal' => NULL), $this->manager->getEnabledPlugins($editor, FALSE), 'Only the "internal" plugin is 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
@@ -106,18 +106,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->getEnabledPlugins($editor), 'The LlamaButton and LlamaContextualAndButton plugins are enabled.');
- $this->assertIdentical(array('internal' => NULL) + $expected, $this->manager->getEnabledPlugins($editor, FALSE), '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][] = 'Underline';
$editor->save();
$expected = array('llama_contextual' => $file['c'], 'llama_contextual_and_button' => $file['cb']);
$this->assertIdentical($expected, $this->manager->getEnabledPlugins($editor), 'The LLamaContextual and LlamaContextualAndButton plugins are enabled.');
- $this->assertIdentical(array('internal' => NULL) + $expected, $this->manager->getEnabledPlugins($editor, FALSE), '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->getEnabledPlugins($editor), 'The LlamaButton, LlamaContextual and LlamaContextualAndButton plugins are enabled.');
- $this->assertIdentical(array('internal' => NULL) + $expected, $this->manager->getEnabledPlugins($editor, FALSE), '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 6993c7e..db2af6f 100644
--- a/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php
+++ b/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php
@@ -88,7 +88,7 @@ function testGetJSSettings() {
'toolbar' => $this->getDefaultToolbarConfig(),
'contentsCss' => $this->getDefaultContentsCssConfig(),
'extraPlugins' => '',
- 'language' => '',
+ 'language' => 'en',
'drupalExternalPlugins' => array(),
);
$this->assertIdentical($expected_config, $this->ckeditor->getJSSettings($editor), 'Generated JS settings are correct for default configuration.');