Update core 8.3.0

This commit is contained in:
Rob Davies 2017-04-13 15:53:35 +01:00
parent da7a7918f8
commit cd7a898e66
6144 changed files with 132297 additions and 87747 deletions

View file

@ -29,8 +29,8 @@ function template_preprocess_ckeditor_settings_toolbar(&$variables) {
// Create lists of active and disabled buttons.
$editor = $variables['editor'];
$plugins = $variables['plugins'];
$buttons = array();
$multiple_buttons = array();
$buttons = [];
$multiple_buttons = [];
foreach ($plugins as $plugin_buttons) {
foreach ($plugin_buttons as $button_name => $button) {
$button['name'] = $button_name;
@ -40,11 +40,11 @@ function template_preprocess_ckeditor_settings_toolbar(&$variables) {
$buttons[$button_name] = $button;
}
}
$button_groups = array();
$active_buttons = array();
$button_groups = [];
$active_buttons = [];
$settings = $editor->getSettings();
foreach ($settings['toolbar']['rows'] as $row_number => $row) {
$button_groups[$row_number] = array();
$button_groups[$row_number] = [];
foreach ($row as $group) {
foreach ($group['items'] as $button_name) {
if (isset($buttons[$button_name])) {
@ -75,31 +75,31 @@ function template_preprocess_ckeditor_settings_toolbar(&$variables) {
$value = $button['image_alternative'];
}
elseif (isset($button['image']) || isset($button['image' . $rtl])) {
$value = array(
$value = [
'#theme' => 'image',
'#uri' => isset($button['image' . $rtl]) ? $button['image' . $rtl] : $button['image'],
'#title' => $button['label'],
'#prefix' => '<a href="#" role="button" title="' . $button['label'] . '" aria-label="' . $button['label'] . '"><span class="cke_button_icon">',
'#suffix' => '</span></a>',
);
];
}
else {
$value = '?';
}
// Build the button attributes.
$attributes = array(
$attributes = [
'data-drupal-ckeditor-button-name' => $button['name'],
);
];
if (!empty($button['attributes'])) {
$attributes = array_merge($attributes, $button['attributes']);
}
// Build the button item.
$button_item = array(
$button_item = [
'value' => $value,
'attributes' => new Attribute($attributes),
);
];
// If this button has group information, add it to the attributes.
if (!empty($button['group'])) {
$button_item['group'] = $button['group'];
@ -114,14 +114,14 @@ function template_preprocess_ckeditor_settings_toolbar(&$variables) {
};
// Assemble list of disabled buttons (which are always a single row).
$variables['active_buttons'] = array();
$variables['active_buttons'] = [];
foreach ($active_buttons as $row_number => $button_row) {
foreach ($button_groups[$row_number] as $group_name) {
$group_name = (string) $group_name;
$variables['active_buttons'][$row_number][$group_name] = array(
$variables['active_buttons'][$row_number][$group_name] = [
'group_name_class' => Html::getClass($group_name),
'buttons' => array(),
);
'buttons' => [],
];
$buttons = array_filter($button_row, function ($button) use ($group_name) {
return (string) $button['group'] === $group_name;
});
@ -131,12 +131,12 @@ function template_preprocess_ckeditor_settings_toolbar(&$variables) {
}
}
// Assemble list of disabled buttons (which are always a single row).
$variables['disabled_buttons'] = array();
$variables['disabled_buttons'] = [];
foreach ($disabled_buttons as $button) {
$variables['disabled_buttons'][] = $build_button_item($button, $rtl);
}
// Assemble list of multiple buttons that may be added multiple times.
$variables['multiple_buttons'] = array();
$variables['multiple_buttons'] = [];
foreach ($multiple_buttons as $button) {
$variables['multiple_buttons'][] = $build_button_item($button, $rtl);
}

View file

@ -44,7 +44,7 @@ drupal.ckeditor.admin:
css:
theme:
css/ckeditor.admin.css: {}
/core/assets/vendor/ckeditor/skins/moono/editor.css: {}
/core/assets/vendor/ckeditor/skins/moono-lisa/editor.css: {}
dependencies:
- core/jquery
- core/drupal

View file

@ -17,21 +17,21 @@ function ckeditor_help($route_name, RouteMatchInterface $route_match) {
case 'help.page.ckeditor':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The CKEditor module provides a highly-accessible, highly-usable visual text editor and adds a toolbar to text fields. Users can use buttons to format content and to create semantically correct and valid HTML. The CKEditor module uses the framework provided by the <a href=":text_editor">Text Editor module</a>. It requires JavaScript to be enabled in the browser. For more information, see the <a href=":doc_url">online documentation for the CKEditor module</a> and the <a href=":cke_url">CKEditor website</a>.', array( ':doc_url' => 'https://www.drupal.org/documentation/modules/ckeditor', ':cke_url' => 'http://ckeditor.com', ':text_editor' => \Drupal::url('help.page', array('name' => 'editor')))) . '</p>';
$output .= '<p>' . t('The CKEditor module provides a highly-accessible, highly-usable visual text editor and adds a toolbar to text fields. Users can use buttons to format content and to create semantically correct and valid HTML. The CKEditor module uses the framework provided by the <a href=":text_editor">Text Editor module</a>. It requires JavaScript to be enabled in the browser. For more information, see the <a href=":doc_url">online documentation for the CKEditor module</a> and the <a href=":cke_url">CKEditor website</a>.', [ ':doc_url' => 'https://www.drupal.org/documentation/modules/ckeditor', ':cke_url' => 'http://ckeditor.com', ':text_editor' => \Drupal::url('help.page', ['name' => 'editor'])]) . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Enabling CKEditor for individual text formats') . '</dt>';
$output .= '<dd>' . t('CKEditor has to be enabled and configured separately for individual text formats from the <a href=":formats">Text formats and editors page</a> because the filter settings for each text format can be different. For more information, see the <a href=":text_editor">Text Editor help page</a> and <a href=":filter">Filter help page</a>.', array(':formats' => \Drupal::url('filter.admin_overview'), ':text_editor' => \Drupal::url('help.page', array('name' => 'editor')), ':filter' => \Drupal::url('help.page', array('name' => 'filter')))) . '</dd>';
$output .= '<dd>' . t('CKEditor has to be enabled and configured separately for individual text formats from the <a href=":formats">Text formats and editors page</a> because the filter settings for each text format can be different. For more information, see the <a href=":text_editor">Text Editor help page</a> and <a href=":filter">Filter help page</a>.', [':formats' => \Drupal::url('filter.admin_overview'), ':text_editor' => \Drupal::url('help.page', ['name' => 'editor']), ':filter' => \Drupal::url('help.page', ['name' => 'filter'])]) . '</dd>';
$output .= '<dt>' . t('Configuring the toolbar') . '</dt>';
$output .= '<dd>' . t('When CKEditor is chosen from the <em>Text editor</em> drop-down menu, its toolbar configuration is displayed. You can add and remove buttons from the <em>Active toolbar</em> by dragging and dropping them, and additional rows can be added to organize the buttons.') . '</dd>';
$output .= '<dt>' . t('Formatting content') . '</dt>';
$output .= '<dd>' . t('CKEditor only allow users to format content in accordance with the filter configuration of the specific text format. If a text format excludes certain HTML tags, the corresponding toolbar buttons are not displayed to users when they edit a text field in this format. For more information see the <a href=":filter">Filter help page</a>.', array(':filter' => \Drupal::url('help.page', array('name' => 'filter')))) . '</dd>';
$output .= '<dd>' . t('CKEditor only allow users to format content in accordance with the filter configuration of the specific text format. If a text format excludes certain HTML tags, the corresponding toolbar buttons are not displayed to users when they edit a text field in this format. For more information see the <a href=":filter">Filter help page</a>.', [':filter' => \Drupal::url('help.page', ['name' => 'filter'])]) . '</dd>';
$output .= '<dt>' . t('Toggling between formatted text and HTML source') . '</dt>';
$output .= '<dd>' . t('If the <em>Source</em> button is available in the toolbar, users can click this button to disable the visual editor and edit the HTML source directly. After toggling back, the visual editor uses the allowed HTML tags to format the text — independent of whether buttons for these tags are available in the toolbar. If the text format is set to <em>limit the use of HTML tags</em>, then all excluded tags will be stripped out of the HTML source when the user toggles back to the text editor.') . '</dd>';
$output .= '<dt>' . t('Check my spelling as I type') . '</dt>';
$output .= '<dd>' . t('By default, CKEditor is configured to leverage your browser\'s spell check capability. Make sure your browser\'s spell checker is enabled in your browser\'s settings. To access suggested corrections for misspelled words, it may be necessary to hold the <em>Control</em> or <em>command</em> (Mac) key while right-clicking the misspelling.') . '</dd>';
$output .= '<dt>' . t('Accessibility features') . '</dt>';
$output .= '<dd>' . t('The built in WYSIWYG editor (CKEditor) comes with a number of <a href=":features">accessibility features</a>. CKEditor comes with built in <a href=":shortcuts">keyboard shortcuts</a>, which can be beneficial for both power users and keyboard only users.', array(':features' => 'http://docs.ckeditor.com/#!/guide/dev_a11y', ':shortcuts' => 'http://docs.ckeditor.com/#!/guide/dev_shortcuts')) . '</dd>';
$output .= '<dd>' . t('The built in WYSIWYG editor (CKEditor) comes with a number of <a href=":features">accessibility features</a>. CKEditor comes with built in <a href=":shortcuts">keyboard shortcuts</a>, which can be beneficial for both power users and keyboard only users.', [':features' => 'http://docs.ckeditor.com/#!/guide/dev_a11y', ':shortcuts' => 'http://docs.ckeditor.com/#!/guide/dev_shortcuts']) . '</dd>';
$output .= '<dt>' . t('Generating accessible content') . '</dt>';
$output .= '<dd>' . t('HTML tables can be created with both table headers as well as caption/summary elements. Alt text is required by default on images added through CKEditor (note that this can be overridden). Semantic HTML5 figure/figcaption are available to add captions to images.') . '</dd>';
$output .= '</dl>';
@ -43,12 +43,12 @@ function ckeditor_help($route_name, RouteMatchInterface $route_match) {
* Implements hook_theme().
*/
function ckeditor_theme() {
return array(
'ckeditor_settings_toolbar' => array(
return [
'ckeditor_settings_toolbar' => [
'file' => 'ckeditor.admin.inc',
'variables' => array('editor' => NULL, 'plugins' => NULL),
),
);
'variables' => ['editor' => NULL, 'plugins' => NULL],
],
];
}
/**
@ -79,7 +79,7 @@ function ckeditor_ckeditor_css_alter(array &$css, Editor $editor) {
* @endcode
*/
function _ckeditor_theme_css($theme = NULL) {
$css = array();
$css = [];
if (!isset($theme)) {
$theme = \Drupal::config('system.theme')->get('default');
}

View file

@ -3,7 +3,7 @@
* CKEditor implementation of {@link Drupal.editors} API.
*/
(function (Drupal, debounce, CKEDITOR, $) {
(function (Drupal, debounce, CKEDITOR, $, displace, AjaxCommands) {
'use strict';
@ -85,6 +85,26 @@
editor.on('change', debounce(function () {
callback(editor.getData());
}, 400));
// A temporary workaround to control scrollbar appearance when using
// autoGrow event to control editor's height.
// @todo Remove when http://dev.ckeditor.com/ticket/12120 is fixed.
editor.on('mode', function () {
var editable = editor.editable();
if (!editable.isInline()) {
editor.on('autoGrow', function (evt) {
var doc = evt.editor.document;
var scrollable = CKEDITOR.env.quirks ? doc.getBody() : doc.getDocumentElement();
if (scrollable.$.scrollHeight < scrollable.$.clientHeight) {
scrollable.setStyle('overflow-y', 'hidden');
}
else {
scrollable.removeStyle('overflow-y');
}
}, null, null, 10000);
}
});
}
return !!editor;
},
@ -273,6 +293,11 @@
}
});
// Formulate a default formula for the maximum autoGrow height.
$(document).on('drupalViewportOffsetChange', function () {
CKEDITOR.config.autoGrow_maxHeight = 0.7 * (window.innerHeight - displace.offsets.top - displace.offsets.bottom);
});
// Redirect on hash change when the original hash has an associated CKEditor.
function redirectTextareaFragmentToCKEditorInstance() {
var hash = location.hash.substr(1);
@ -287,7 +312,39 @@
}
$(window).on('hashchange.ckeditor', redirectTextareaFragmentToCKEditorInstance);
// Set autoGrow to make the editor grow the moment it is created.
CKEDITOR.config.autoGrow_onStartup = true;
// Set the CKEditor cache-busting string to the same value as Drupal.
CKEDITOR.timestamp = drupalSettings.ckeditor.timestamp;
})(Drupal, Drupal.debounce, CKEDITOR, jQuery);
if (AjaxCommands) {
/**
* Command to add style sheets to a CKEditor instance.
*
* Works for both iframe and inline CKEditor instances.
*
* @param {Drupal.Ajax} [ajax]
* {@link Drupal.Ajax} object created by {@link Drupal.ajax}.
* @param {object} response
* The response from the Ajax request.
* @param {string} response.editor_id
* The CKEditor instance ID.
* @param {number} [status]
* The XMLHttpRequest status.
*
* @see http://docs.ckeditor.com/#!/api/CKEDITOR.dom.document
*/
AjaxCommands.prototype.ckeditor_add_stylesheet = function (ajax, response, status) {
var editor = CKEDITOR.instances[response.editor_id];
if (editor) {
response.stylesheets.forEach(function (url) {
editor.document.appendStyleSheet(url);
});
}
};
}
})(Drupal, Drupal.debounce, CKEDITOR, jQuery, Drupal.displace, Drupal.AjaxCommands);

View file

@ -13,7 +13,7 @@
var parsedAttributes = {};
var domElement = element.$;
var attribute = null;
var attribute;
var attributeName;
for (var attrIndex = 0; attrIndex < domElement.attributes.length; attrIndex++) {
attribute = domElement.attributes.item(attrIndex);

View file

@ -144,7 +144,7 @@
};
// Create hidden CKEditor with all features enabled, retrieve metadata.
// @see \Drupal\ckeditor\Plugin\Editor\CKEditor::settingsForm.
// @see \Drupal\ckeditor\Plugin\Editor\CKEditor::buildConfigurationForm().
var hiddenCKEditorID = 'ckeditor-hidden';
if (CKEDITOR.instances[hiddenCKEditorID]) {
CKEDITOR.instances[hiddenCKEditorID].destroy(true);

View file

@ -61,7 +61,7 @@
var $button = $target.parent();
var $container = $button.parent();
var $group = $button.closest('.ckeditor-toolbar-group');
var $row = $button.closest('.ckeditor-row');
var $row;
var containerType = $container.data('drupal-ckeditor-button-sorting');
var $availableButtons = this.$el.find('[data-drupal-ckeditor-button-sorting="source"]');
var $activeButtons = this.$el.find('.ckeditor-toolbar-active');

View file

@ -0,0 +1,64 @@
<?php
namespace Drupal\ckeditor\Ajax;
use Drupal\Core\Ajax\CommandInterface;
/**
* AJAX command to add style sheets to a CKEditor instance.
*/
class AddStyleSheetCommand implements CommandInterface {
/**
* The CKEditor instance ID.
*
* @var string
*/
protected $editorId;
/**
* The style sheet URLs to add to the CKEditor instance.
*
* @var string[]
*/
protected $styleSheets = [];
/**
* AddStyleSheetCommand constructor.
*
* @param string $editor_id
* The CKEditor instance ID.
* @param string[] $stylesheets
* The style sheet URLs to add to the CKEditor instance.
*/
public function __construct($editor_id, array $stylesheets = []) {
$this->editorId = $editor_id;
$this->styleSheets = $stylesheets;
}
/**
* Adds a style sheet to the CKEditor instance.
*
* @param string $stylesheet
* The style sheet URL.
*
* @return $this
* The called object, for chaining.
*/
public function addStyleSheet($stylesheet) {
$this->styleSheets[] = $stylesheet;
return $this;
}
/**
* {@inheritdoc}
*/
public function render() {
return [
'command' => 'ckeditor_add_stylesheet',
'editor_id' => $this->editorId,
'stylesheets' => $this->styleSheets,
];
}
}

View file

@ -33,22 +33,22 @@ abstract class CKEditorPluginBase extends PluginBase implements CKEditorPluginIn
/**
* {@inheritdoc}
*/
function isInternal() {
public function isInternal() {
return FALSE;
}
/**
* {@inheritdoc}
*/
function getDependencies(Editor $editor) {
return array();
public function getDependencies(Editor $editor) {
return [];
}
/**
* {@inheritdoc}
*/
function getLibraries(Editor $editor) {
return array();
public function getLibraries(Editor $editor) {
return [];
}
}

View file

@ -68,8 +68,8 @@ class CKEditorPluginManager extends DefaultPluginManager {
public function getEnabledPluginFiles(Editor $editor, $include_internal_plugins = FALSE) {
$plugins = array_keys($this->getDefinitions());
$toolbar_buttons = $this->getEnabledButtons($editor);
$enabled_plugins = array();
$additional_plugins = array();
$enabled_plugins = [];
$additional_plugins = [];
foreach ($plugins as $plugin_id) {
$plugin = $this->createInstance($plugin_id);
@ -139,7 +139,7 @@ class CKEditorPluginManager extends DefaultPluginManager {
*/
public function getButtons() {
$plugins = array_keys($this->getDefinitions());
$buttons_plugins = array();
$buttons_plugins = [];
foreach ($plugins as $plugin_id) {
$plugin = $this->createInstance($plugin_id);
@ -167,16 +167,16 @@ class CKEditorPluginManager extends DefaultPluginManager {
foreach (array_keys($definitions) as $plugin_id) {
$plugin = $this->createInstance($plugin_id);
if ($plugin instanceof CKEditorPluginConfigurableInterface) {
$plugin_settings_form = array();
$form['plugins'][$plugin_id] = array(
$plugin_settings_form = [];
$form['plugins'][$plugin_id] = [
'#type' => 'details',
'#title' => $definitions[$plugin_id]['label'],
'#open' => TRUE,
'#group' => 'editor][settings][plugin_settings',
'#attributes' => array(
'#attributes' => [
'data-ckeditor-plugin-id' => $plugin_id,
),
);
],
];
// Provide enough metadata for the drupal.ckeditor.admin library to
// allow it to automatically show/hide the vertical tab containing the
// settings for this plugin. Only do this if it's a CKEditor plugin that
@ -206,7 +206,7 @@ class CKEditorPluginManager extends DefaultPluginManager {
*/
public function getCssFiles(Editor $editor) {
$enabled_plugins = array_keys($this->getEnabledPluginFiles($editor, TRUE));
$css_files = array();
$css_files = [];
foreach ($enabled_plugins as $plugin_id) {
$plugin = $this->createInstance($plugin_id);

View file

@ -29,31 +29,31 @@ class DrupalImage extends CKEditorPluginBase implements CKEditorPluginConfigurab
* {@inheritdoc}
*/
public function getLibraries(Editor $editor) {
return array(
return [
'core/drupal.ajax',
);
];
}
/**
* {@inheritdoc}
*/
public function getConfig(Editor $editor) {
return array(
'drupalImage_dialogTitleAdd' => t('Insert Image'),
'drupalImage_dialogTitleEdit' => t('Edit Image'),
);
return [
'drupalImage_dialogTitleAdd' => $this->t('Insert Image'),
'drupalImage_dialogTitleEdit' => $this->t('Edit Image'),
];
}
/**
* {@inheritdoc}
*/
public function getButtons() {
return array(
'DrupalImage' => array(
'label' => t('Image'),
return [
'DrupalImage' => [
'label' => $this->t('Image'),
'image' => drupal_get_path('module', 'ckeditor') . '/js/plugins/drupalimage/icons/drupalimage.png',
),
);
],
];
}
/**
@ -66,7 +66,7 @@ class DrupalImage extends CKEditorPluginBase implements CKEditorPluginConfigurab
$form_state->loadInclude('editor', 'admin.inc');
$form['image_upload'] = editor_image_upload_settings_form($editor);
$form['image_upload']['#attached']['library'][] = 'ckeditor/drupal.ckeditor.drupalimage.admin';
$form['image_upload']['#element_validate'][] = array($this, 'validateImageUploadSettings');
$form['image_upload']['#element_validate'][] = [$this, 'validateImageUploadSettings'];
return $form;
}
@ -79,10 +79,10 @@ class DrupalImage extends CKEditorPluginBase implements CKEditorPluginConfigurab
* @see \Drupal\editor\Form\EditorImageDialog
* @see editor_image_upload_settings_form()
*/
function validateImageUploadSettings(array $element, FormStateInterface $form_state) {
$settings = &$form_state->getValue(array('editor', 'settings', 'plugins', 'drupalimage', 'image_upload'));
public function validateImageUploadSettings(array $element, FormStateInterface $form_state) {
$settings = &$form_state->getValue(['editor', 'settings', 'plugins', 'drupalimage', 'image_upload']);
$form_state->get('editor')->setImageUploadSettings($settings);
$form_state->unsetValue(array('editor', 'settings', 'plugins', 'drupalimage'));
$form_state->unsetValue(['editor', 'settings', 'plugins', 'drupalimage']);
}
}

View file

@ -2,7 +2,7 @@
namespace Drupal\ckeditor\Plugin\CKEditorPlugin;
use Drupal\Component\Plugin\PluginBase;
use Drupal\Core\Plugin\PluginBase;
use Drupal\editor\Entity\Editor;
use Drupal\ckeditor\CKEditorPluginInterface;
use Drupal\ckeditor\CKEditorPluginContextualInterface;
@ -30,16 +30,16 @@ class DrupalImageCaption extends PluginBase implements CKEditorPluginInterface,
* {@inheritdoc}
*/
public function getDependencies(Editor $editor) {
return array();
return [];
}
/**
* {@inheritdoc}
*/
public function getLibraries(Editor $editor) {
return array(
return [
'ckeditor/drupal.ckeditor.plugins.drupalimagecaption',
);
];
}
/**
@ -54,30 +54,30 @@ class DrupalImageCaption extends PluginBase implements CKEditorPluginInterface,
*/
public function getConfig(Editor $editor) {
$format = $editor->getFilterFormat();
return array(
return [
'image2_captionedClass' => 'caption caption-img',
'image2_alignClasses' => array('align-left', 'align-center', 'align-right'),
'drupalImageCaption_captionPlaceholderText' => t('Enter caption here'),
'image2_alignClasses' => ['align-left', 'align-center', 'align-right'],
'drupalImageCaption_captionPlaceholderText' => $this->t('Enter caption here'),
// Only enable those parts of DrupalImageCaption for which the
// corresponding Drupal text filters are enabled.
'drupalImageCaption_captionFilterEnabled' => $format->filters('filter_caption')->status,
'drupalImageCaption_alignFilterEnabled' => $format->filters('filter_align')->status,
);
];
}
/**
* {@inheritdoc}
*/
public function getCssFiles(Editor $editor) {
return array(
return [
drupal_get_path('module', 'ckeditor') . '/css/plugins/drupalimagecaption/ckeditor.drupalimagecaption.css'
);
];
}
/**
* {@inheritdoc}
*/
function isEnabled(Editor $editor) {
public function isEnabled(Editor $editor) {
if (!$editor->hasAssociatedFilterFormat()) {
return FALSE;
}

View file

@ -27,19 +27,19 @@ class DrupalLink extends CKEditorPluginBase {
* {@inheritdoc}
*/
public function getLibraries(Editor $editor) {
return array(
return [
'core/drupal.ajax',
);
];
}
/**
* {@inheritdoc}
*/
public function getConfig(Editor $editor) {
return array(
'drupalLink_dialogTitleAdd' => t('Add Link'),
'drupalLink_dialogTitleEdit' => t('Edit Link'),
);
return [
'drupalLink_dialogTitleAdd' => $this->t('Add Link'),
'drupalLink_dialogTitleEdit' => $this->t('Edit Link'),
];
}
/**
@ -47,16 +47,16 @@ class DrupalLink extends CKEditorPluginBase {
*/
public function getButtons() {
$path = drupal_get_path('module', 'ckeditor') . '/js/plugins/drupallink';
return array(
'DrupalLink' => array(
'label' => t('Link'),
return [
'DrupalLink' => [
'label' => $this->t('Link'),
'image' => $path . '/icons/drupallink.png',
),
'DrupalUnlink' => array(
'label' => t('Unlink'),
],
'DrupalUnlink' => [
'label' => $this->t('Unlink'),
'image' => $path . '/icons/drupalunlink.png',
),
);
],
];
}
}

View file

@ -100,14 +100,14 @@ class Internal extends CKEditorPluginBase implements ContainerFactoryPluginInter
*/
public function getConfig(Editor $editor) {
// Reasonable defaults that provide expected basic behavior.
$config = array(
$config = [
'customConfig' => '', // Don't load CKEditor's config.js file.
'pasteFromWordPromptCleanup' => TRUE,
'resize_dir' => 'vertical',
'justifyClasses' => array('text-align-left', 'text-align-center', 'text-align-right', 'text-align-justify'),
'justifyClasses' => ['text-align-left', 'text-align-center', 'text-align-right', 'text-align-justify'],
'entities' => FALSE,
'disableNativeSpellChecker' => FALSE,
);
];
// Add the allowedContent setting, which ensures CKEditor only allows tags
// and attributes that are allowed by the text format for this text editor.
@ -144,195 +144,195 @@ class Internal extends CKEditorPluginBase implements ContainerFactoryPluginInter
];
};
return array(
return [
// "basicstyles" plugin.
'Bold' => array(
'label' => t('Bold'),
'Bold' => [
'label' => $this->t('Bold'),
'image_alternative' => $button('bold'),
'image_alternative_rtl' => $button('bold', 'rtl'),
),
'Italic' => array(
'label' => t('Italic'),
],
'Italic' => [
'label' => $this->t('Italic'),
'image_alternative' => $button('italic'),
'image_alternative_rtl' => $button('italic', 'rtl'),
),
'Underline' => array(
'label' => t('Underline'),
],
'Underline' => [
'label' => $this->t('Underline'),
'image_alternative' => $button('underline'),
'image_alternative_rtl' => $button('underline', 'rtl'),
),
'Strike' => array(
'label' => t('Strike-through'),
],
'Strike' => [
'label' => $this->t('Strike-through'),
'image_alternative' => $button('strike'),
'image_alternative_rtl' => $button('strike', 'rtl'),
),
'Superscript' => array(
'label' => t('Superscript'),
],
'Superscript' => [
'label' => $this->t('Superscript'),
'image_alternative' => $button('super script'),
'image_alternative_rtl' => $button('super script', 'rtl'),
),
'Subscript' => array(
'label' => t('Subscript'),
],
'Subscript' => [
'label' => $this->t('Subscript'),
'image_alternative' => $button('sub script'),
'image_alternative_rtl' => $button('sub script', 'rtl'),
),
],
// "removeformat" plugin.
'RemoveFormat' => array(
'label' => t('Remove format'),
'RemoveFormat' => [
'label' => $this->t('Remove format'),
'image_alternative' => $button('remove format'),
'image_alternative_rtl' => $button('remove format', 'rtl'),
),
],
// "justify" plugin.
'JustifyLeft' => array(
'label' => t('Align left'),
'JustifyLeft' => [
'label' => $this->t('Align left'),
'image_alternative' => $button('justify left'),
'image_alternative_rtl' => $button('justify left', 'rtl'),
),
'JustifyCenter' => array(
'label' => t('Align center'),
],
'JustifyCenter' => [
'label' => $this->t('Align center'),
'image_alternative' => $button('justify center'),
'image_alternative_rtl' => $button('justify center', 'rtl'),
),
'JustifyRight' => array(
'label' => t('Align right'),
],
'JustifyRight' => [
'label' => $this->t('Align right'),
'image_alternative' => $button('justify right'),
'image_alternative_rtl' => $button('justify right', 'rtl'),
),
'JustifyBlock' => array(
'label' => t('Justify'),
],
'JustifyBlock' => [
'label' => $this->t('Justify'),
'image_alternative' => $button('justify block'),
'image_alternative_rtl' => $button('justify block', 'rtl'),
),
],
// "list" plugin.
'BulletedList' => array(
'label' => t('Bullet list'),
'BulletedList' => [
'label' => $this->t('Bullet list'),
'image_alternative' => $button('bulleted list'),
'image_alternative_rtl' => $button('bulleted list', 'rtl'),
),
'NumberedList' => array(
'label' => t('Numbered list'),
],
'NumberedList' => [
'label' => $this->t('Numbered list'),
'image_alternative' => $button('numbered list'),
'image_alternative_rtl' => $button('numbered list', 'rtl'),
),
],
// "indent" plugin.
'Outdent' => array(
'label' => t('Outdent'),
'Outdent' => [
'label' => $this->t('Outdent'),
'image_alternative' => $button('outdent'),
'image_alternative_rtl' => $button('outdent', 'rtl'),
),
'Indent' => array(
'label' => t('Indent'),
],
'Indent' => [
'label' => $this->t('Indent'),
'image_alternative' => $button('indent'),
'image_alternative_rtl' => $button('indent', 'rtl'),
),
],
// "undo" plugin.
'Undo' => array(
'label' => t('Undo'),
'Undo' => [
'label' => $this->t('Undo'),
'image_alternative' => $button('undo'),
'image_alternative_rtl' => $button('undo', 'rtl'),
),
'Redo' => array(
'label' => t('Redo'),
],
'Redo' => [
'label' => $this->t('Redo'),
'image_alternative' => $button('redo'),
'image_alternative_rtl' => $button('redo', 'rtl'),
),
],
// "blockquote" plugin.
'Blockquote' => array(
'label' => t('Blockquote'),
'Blockquote' => [
'label' => $this->t('Blockquote'),
'image_alternative' => $button('blockquote'),
'image_alternative_rtl' => $button('blockquote', 'rtl'),
),
],
// "horizontalrule" plugin
'HorizontalRule' => array(
'label' => t('Horizontal rule'),
'HorizontalRule' => [
'label' => $this->t('Horizontal rule'),
'image_alternative' => $button('horizontal rule'),
'image_alternative_rtl' => $button('horizontal rule', 'rtl'),
),
],
// "clipboard" plugin.
'Cut' => array(
'label' => t('Cut'),
'Cut' => [
'label' => $this->t('Cut'),
'image_alternative' => $button('cut'),
'image_alternative_rtl' => $button('cut', 'rtl'),
),
'Copy' => array(
'label' => t('Copy'),
],
'Copy' => [
'label' => $this->t('Copy'),
'image_alternative' => $button('copy'),
'image_alternative_rtl' => $button('copy', 'rtl'),
),
'Paste' => array(
'label' => t('Paste'),
],
'Paste' => [
'label' => $this->t('Paste'),
'image_alternative' => $button('paste'),
'image_alternative_rtl' => $button('paste', 'rtl'),
),
],
// "pastetext" plugin.
'PasteText' => array(
'label' => t('Paste Text'),
'PasteText' => [
'label' => $this->t('Paste Text'),
'image_alternative' => $button('paste text'),
'image_alternative_rtl' => $button('paste text', 'rtl'),
),
],
// "pastefromword" plugin.
'PasteFromWord' => array(
'label' => t('Paste from Word'),
'PasteFromWord' => [
'label' => $this->t('Paste from Word'),
'image_alternative' => $button('paste from word'),
'image_alternative_rtl' => $button('paste from word', 'rtl'),
),
],
// "specialchar" plugin.
'SpecialChar' => array(
'label' => t('Character map'),
'SpecialChar' => [
'label' => $this->t('Character map'),
'image_alternative' => $button('special char'),
'image_alternative_rtl' => $button('special char', 'rtl'),
),
'Format' => array(
'label' => t('HTML block format'),
],
'Format' => [
'label' => $this->t('HTML block format'),
'image_alternative' => [
'#type' => 'inline_template',
'#template' => '<a href="#" role="button" aria-label="{{ format_text }}"><span class="ckeditor-button-dropdown">{{ format_text }}<span class="ckeditor-button-arrow"></span></span></a>',
'#context' => [
'format_text' => t('Format'),
'format_text' => $this->t('Format'),
],
],
),
],
// "table" plugin.
'Table' => array(
'label' => t('Table'),
'Table' => [
'label' => $this->t('Table'),
'image_alternative' => $button('table'),
'image_alternative_rtl' => $button('table', 'rtl'),
),
],
// "showblocks" plugin.
'ShowBlocks' => array(
'label' => t('Show blocks'),
'ShowBlocks' => [
'label' => $this->t('Show blocks'),
'image_alternative' => $button('show blocks'),
'image_alternative_rtl' => $button('show blocks', 'rtl'),
),
],
// "sourcearea" plugin.
'Source' => array(
'label' => t('Source code'),
'Source' => [
'label' => $this->t('Source code'),
'image_alternative' => $button('source'),
'image_alternative_rtl' => $button('source', 'rtl'),
),
],
// "maximize" plugin.
'Maximize' => array(
'label' => t('Maximize'),
'Maximize' => [
'label' => $this->t('Maximize'),
'image_alternative' => $button('maximize'),
'image_alternative_rtl' => $button('maximize', 'rtl'),
),
],
// No plugin, separator "button" for toolbar builder UI use only.
'-' => array(
'label' => t('Separator'),
'-' => [
'label' => $this->t('Separator'),
'image_alternative' => [
'#type' => 'inline_template',
'#template' => '<a href="#" role="button" aria-label="{{ button_separator_text }}" class="ckeditor-separator"></a>',
'#context' => [
'button_separator_text' => t('Button separator'),
'button_separator_text' => $this->t('Button separator'),
],
],
'attributes' => array(
'class' => array('ckeditor-button-separator'),
'attributes' => [
'class' => ['ckeditor-button-separator'],
'data-drupal-ckeditor-type' => 'separator',
),
],
'multiple' => TRUE,
),
);
],
];
}
/**
@ -350,7 +350,7 @@ class Internal extends CKEditorPluginBase implements ContainerFactoryPluginInter
// When no text format is associated yet, assume no tag is allowed.
// @see \Drupal\Editor\EditorInterface::hasAssociatedFilterFormat()
if (!$editor->hasAssociatedFilterFormat()) {
return array();
return [];
}
$format = $editor->getFilterFormat();
@ -416,7 +416,7 @@ class Internal extends CKEditorPluginBase implements ContainerFactoryPluginInter
// When nothing is disallowed, set allowedContent to true.
if (!in_array(FilterInterface::TYPE_HTML_RESTRICTOR, $filter_types)) {
return array(TRUE, FALSE);
return [TRUE, FALSE];
}
// Generate setting that accurately reflects allowed tags and attributes.
else {
@ -441,10 +441,10 @@ class Internal extends CKEditorPluginBase implements ContainerFactoryPluginInter
// When all HTML is allowed, also set allowedContent to true and
// disallowedContent to false.
if ($html_restrictions === FALSE) {
return array(TRUE, FALSE);
return [TRUE, FALSE];
}
$allowed = array();
$disallowed = array();
$allowed = [];
$disallowed = [];
if (isset($html_restrictions['forbidden_tags'])) {
foreach ($html_restrictions['forbidden_tags'] as $tag) {
$disallowed[$tag] = TRUE;
@ -453,11 +453,11 @@ class Internal extends CKEditorPluginBase implements ContainerFactoryPluginInter
foreach ($html_restrictions['allowed'] as $tag => $attributes) {
// Tell CKEditor the tag is allowed, but no attributes.
if ($attributes === FALSE) {
$allowed[$tag] = array(
$allowed[$tag] = [
'attributes' => FALSE,
'styles' => FALSE,
'classes' => FALSE,
);
];
}
// Tell CKEditor the tag is allowed, as well as any attribute on it. The
// "style" and "class" attributes are handled separately by CKEditor:
@ -465,11 +465,11 @@ class Internal extends CKEditorPluginBase implements ContainerFactoryPluginInter
// attributes, unless you state specific values for them that are
// allowed. Or, in this case: any value for them is allowed.
elseif ($attributes === TRUE) {
$allowed[$tag] = array(
$allowed[$tag] = [
'attributes' => TRUE,
'styles' => TRUE,
'classes' => TRUE,
);
];
// We've just marked that any value for the "style" and "class"
// attributes is allowed. However, that may not be the case: the "*"
// tag may still apply restrictions.
@ -518,11 +518,11 @@ class Internal extends CKEditorPluginBase implements ContainerFactoryPluginInter
elseif (is_array($attributes)) {
// Set defaults (these will be overridden below if more specific
// values are present).
$allowed[$tag] = array(
$allowed[$tag] = [
'attributes' => FALSE,
'styles' => FALSE,
'classes' => FALSE,
);
];
// Configure allowed attributes, allowed "style" attribute values and
// allowed "class" attribute values.
// CKEditor only allows specific values for the "class" and "style"
@ -600,7 +600,7 @@ class Internal extends CKEditorPluginBase implements ContainerFactoryPluginInter
ksort($allowed);
ksort($disallowed);
return array($allowed, $disallowed);
return [$allowed, $disallowed];
}
}

View file

@ -104,7 +104,7 @@ class Language extends CKEditorPluginBase implements CKEditorPluginConfigurableI
}
$predefined_languages = LanguageManager::getStandardLanguageList();
$form['language_list'] = array(
$form['language_list'] = [
'#title' => $this->t('Language list'),
'#title_display' => 'invisible',
'#type' => 'select',
@ -118,7 +118,7 @@ class Language extends CKEditorPluginBase implements CKEditorPluginConfigurableI
'@count' => count($predefined_languages),
]),
'#attached' => ['library' => ['ckeditor/drupal.ckeditor.language.admin']],
);
];
return $form;
}
@ -126,10 +126,10 @@ class Language extends CKEditorPluginBase implements CKEditorPluginConfigurableI
/**
* {@inheritdoc}
*/
function getCssFiles(Editor $editor) {
return array(
public function getCssFiles(Editor $editor) {
return [
drupal_get_path('module', 'ckeditor') . '/css/plugins/language/ckeditor.language.css'
);
];
}
}

View file

@ -36,7 +36,7 @@ class StylesCombo extends CKEditorPluginBase implements CKEditorPluginConfigurab
* {@inheritdoc}
*/
public function getConfig(Editor $editor) {
$config = array();
$config = [];
$settings = $editor->getSettings();
if (!isset($settings['plugins']['stylescombo']['styles'])) {
return $config;
@ -50,18 +50,18 @@ class StylesCombo extends CKEditorPluginBase implements CKEditorPluginConfigurab
* {@inheritdoc}
*/
public function getButtons() {
return array(
'Styles' => array(
'label' => t('Font style'),
return [
'Styles' => [
'label' => $this->t('Font style'),
'image_alternative' => [
'#type' => 'inline_template',
'#template' => '<a href="#" role="button" aria-label="{{ styles_text }}"><span class="ckeditor-button-dropdown">{{ styles_text }}<span class="ckeditor-button-arrow"></span></span></a>',
'#context' => [
'styles_text' => t('Styles'),
'styles_text' => $this->t('Styles'),
],
],
),
);
],
];
}
/**
@ -69,25 +69,25 @@ class StylesCombo extends CKEditorPluginBase implements CKEditorPluginConfigurab
*/
public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {
// Defaults.
$config = array('styles' => '');
$config = ['styles' => ''];
$settings = $editor->getSettings();
if (isset($settings['plugins']['stylescombo'])) {
$config = $settings['plugins']['stylescombo'];
}
$form['styles'] = array(
'#title' => t('Styles'),
$form['styles'] = [
'#title' => $this->t('Styles'),
'#title_display' => 'invisible',
'#type' => 'textarea',
'#default_value' => $config['styles'],
'#description' => t('A list of classes that will be provided in the "Styles" dropdown. Enter one or more classes on each line in the format: element.classA.classB|Label. Example: h1.title|Title. Advanced example: h1.fancy.title|Fancy title.<br />These styles should be available in your theme\'s CSS file.'),
'#attached' => array(
'library' => array('ckeditor/drupal.ckeditor.stylescombo.admin'),
),
'#element_validate' => array(
array($this, 'validateStylesValue'),
),
);
'#description' => $this->t('A list of classes that will be provided in the "Styles" dropdown. Enter one or more classes on each line in the format: element.classA.classB|Label. Example: h1.title|Title. Advanced example: h1.fancy.title|Fancy title.<br />These styles should be available in your theme\'s CSS file.'),
'#attached' => [
'library' => ['ckeditor/drupal.ckeditor.stylescombo.admin'],
],
'#element_validate' => [
[$this, 'validateStylesValue'],
],
];
return $form;
}
@ -98,12 +98,12 @@ class StylesCombo extends CKEditorPluginBase implements CKEditorPluginConfigurab
public function validateStylesValue(array $element, FormStateInterface $form_state) {
$styles_setting = $this->generateStylesSetSetting($element['#value']);
if ($styles_setting === FALSE) {
$form_state->setError($element, t('The provided list of styles is syntactically incorrect.'));
$form_state->setError($element, $this->t('The provided list of styles is syntactically incorrect.'));
}
else {
$style_names = array_map(function ($style) { return $style['name']; }, $styles_setting);
if (count($style_names) !== count(array_unique($style_names))) {
$form_state->setError($element, t('Each style must have a unique label.'));
$form_state->setError($element, $this->t('Each style must have a unique label.'));
}
}
}
@ -120,7 +120,7 @@ class StylesCombo extends CKEditorPluginBase implements CKEditorPluginConfigurab
* syntax is invalid.
*/
protected function generateStylesSetSetting($styles) {
$styles_set = array();
$styles_set = [];
// Early-return when empty.
$styles = trim($styles);
@ -128,7 +128,7 @@ class StylesCombo extends CKEditorPluginBase implements CKEditorPluginConfigurab
return $styles_set;
}
$styles = str_replace(array("\r\n", "\r"), "\n", $styles);
$styles = str_replace(["\r\n", "\r"], "\n", $styles);
foreach (explode("\n", $styles) as $style) {
$style = trim($style);
@ -149,14 +149,14 @@ class StylesCombo extends CKEditorPluginBase implements CKEditorPluginConfigurab
// Build the data structure CKEditor's stylescombo plugin expects.
// @see http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Styles
$configured_style = array(
$configured_style = [
'name' => trim($label),
'element' => trim($element),
);
];
if (!empty($classes)) {
$configured_style['attributes'] = array(
$configured_style['attributes'] = [
'class' => implode(' ', array_map('trim', $classes))
);
];
}
$styles_set[] = $configured_style;
}

View file

@ -102,36 +102,36 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface {
* {@inheritdoc}
*/
public function getDefaultSettings() {
return array(
'toolbar' => array(
'rows' => array(
return [
'toolbar' => [
'rows' => [
// Button groups.
array(
array(
'name' => t('Formatting'),
'items' => array('Bold', 'Italic',),
),
array(
'name' => t('Links'),
'items' => array('DrupalLink', 'DrupalUnlink',),
),
array(
'name' => t('Lists'),
'items' => array('BulletedList', 'NumberedList',),
),
array(
'name' => t('Media'),
'items' => array('Blockquote', 'DrupalImage',),
),
array(
'name' => t('Tools'),
'items' => array('Source',),
),
),
),
),
[
[
'name' => $this->t('Formatting'),
'items' => ['Bold', 'Italic'],
],
[
'name' => $this->t('Links'),
'items' => ['DrupalLink', 'DrupalUnlink'],
],
[
'name' => $this->t('Lists'),
'items' => ['BulletedList', 'NumberedList'],
],
[
'name' => $this->t('Media'),
'items' => ['Blockquote', 'DrupalImage'],
],
[
'name' => $this->t('Tools'),
'items' => ['Source'],
],
],
],
],
'plugins' => ['language' => ['language_list' => 'un']],
);
];
}
/**
@ -140,39 +140,39 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface {
public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {
$settings = $editor->getSettings();
$ckeditor_settings_toolbar = array(
$ckeditor_settings_toolbar = [
'#theme' => 'ckeditor_settings_toolbar',
'#editor' => $editor,
'#plugins' => $this->ckeditorPluginManager->getButtons(),
);
$form['toolbar'] = array(
];
$form['toolbar'] = [
'#type' => 'container',
'#attached' => array(
'library' => array('ckeditor/drupal.ckeditor.admin'),
'#attached' => [
'library' => ['ckeditor/drupal.ckeditor.admin'],
'drupalSettings' => [
'ckeditor' => [
'toolbarAdmin' => (string) $this->renderer->renderPlain($ckeditor_settings_toolbar),
],
],
),
'#attributes' => array('class' => array('ckeditor-toolbar-configuration')),
);
],
'#attributes' => ['class' => ['ckeditor-toolbar-configuration']],
];
$form['toolbar']['button_groups'] = array(
$form['toolbar']['button_groups'] = [
'#type' => 'textarea',
'#title' => t('Toolbar buttons'),
'#title' => $this->t('Toolbar buttons'),
'#default_value' => json_encode($settings['toolbar']['rows']),
'#attributes' => array('class' => array('ckeditor-toolbar-textarea')),
);
'#attributes' => ['class' => ['ckeditor-toolbar-textarea']],
];
// CKEditor plugin settings, if any.
$form['plugin_settings'] = array(
$form['plugin_settings'] = [
'#type' => 'vertical_tabs',
'#title' => t('CKEditor plugin settings'),
'#attributes' => array(
'#title' => $this->t('CKEditor plugin settings'),
'#attributes' => [
'id' => 'ckeditor-plugin-settings',
),
);
],
];
$this->ckeditorPluginManager->injectPluginSettingsForm($form, $form_state, $editor);
if (count(Element::children($form['plugins'])) === 0) {
unset($form['plugins']);
@ -186,7 +186,7 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface {
// settings to be updated accordingly.
// Get a list of all external plugins and their corresponding files.
$plugins = array_keys($this->ckeditorPluginManager->getDefinitions());
$all_external_plugins = array();
$all_external_plugins = [];
foreach ($plugins as $plugin_id) {
$plugin = $this->ckeditorPluginManager->createInstance($plugin_id);
if (!$plugin->isInternal()) {
@ -196,37 +196,37 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface {
// Get a list of all buttons that are provided by all plugins.
$all_buttons = array_reduce($this->ckeditorPluginManager->getButtons(), function($result, $item) {
return array_merge($result, array_keys($item));
}, array());
}, []);
// Build a fake Editor object, which we'll use to generate JavaScript
// settings for this fake Editor instance.
$fake_editor = Editor::create(array(
$fake_editor = Editor::create([
'format' => $editor->id(),
'editor' => 'ckeditor',
'settings' => array(
'settings' => [
// Single toolbar row, single button group, all existing buttons.
'toolbar' => array(
'rows' => array(
0 => array(
0 => array(
'toolbar' => [
'rows' => [
0 => [
0 => [
'name' => 'All existing buttons',
'items' => $all_buttons,
)
)
),
),
]
]
],
],
'plugins' => $settings['plugins'],
),
));
],
]);
$config = $this->getJSSettings($fake_editor);
// Remove the ACF configuration that is generated based on filter settings,
// because otherwise we cannot retrieve per-feature metadata.
unset($config['allowedContent']);
$form['hidden_ckeditor'] = array(
$form['hidden_ckeditor'] = [
'#markup' => '<div id="ckeditor-hidden" class="hidden"></div>',
'#attached' => array(
'#attached' => [
'drupalSettings' => ['ckeditor' => ['hiddenCKEditorConfig' => $config]],
),
);
],
];
return $form;
}
@ -238,7 +238,7 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface {
// Modify the toolbar settings by reference. The values in
// $form_state->getValue(array('editor', 'settings')) will be saved directly
// by editor_form_filter_admin_format_submit().
$toolbar_settings = &$form_state->getValue(array('editor', 'settings', 'toolbar'));
$toolbar_settings = &$form_state->getValue(['editor', 'settings', 'toolbar']);
// The rows key is not built into the form structure, so decode the button
// groups data into this new key and remove the button_groups key.
@ -246,8 +246,8 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface {
unset($toolbar_settings['button_groups']);
// Remove the plugin settings' vertical tabs state; no need to save that.
if ($form_state->hasValue(array('editor', 'settings', 'plugins'))) {
$form_state->unsetValue(array('editor', 'settings', 'plugin_settings'));
if ($form_state->hasValue(['editor', 'settings', 'plugins'])) {
$form_state->unsetValue(['editor', 'settings', 'plugin_settings']);
}
}
@ -255,7 +255,7 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface {
* {@inheritdoc}
*/
public function getJSSettings(Editor $editor) {
$settings = array();
$settings = [];
// Get the settings for all enabled plugins, even the internal ones.
$enabled_plugins = array_keys($this->ckeditorPluginManager->getEnabledPluginFiles($editor, TRUE));
@ -279,7 +279,7 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface {
// Next, set the most fundamental CKEditor settings.
$external_plugin_files = $this->ckeditorPluginManager->getEnabledPluginFiles($editor);
$settings += array(
$settings += [
'toolbar' => $this->buildToolbarJSSetting($editor),
'contentsCss' => $this->buildContentsCssJSSetting($editor),
'extraPlugins' => implode(',', array_keys($external_plugin_files)),
@ -290,15 +290,15 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface {
// styles.js by default.
// See http://dev.ckeditor.com/ticket/9992#comment:9.
'stylesSet' => FALSE,
);
];
// Finally, set Drupal-specific CKEditor settings.
$root_relative_file_url = function ($uri) {
return file_url_transform_relative(file_create_url($uri));
};
$settings += array(
$settings += [
'drupalExternalPlugins' => array_map($root_relative_file_url, $external_plugin_files),
);
];
// Parse all CKEditor plugin JavaScript files for translations.
if ($this->moduleHandler->moduleExists('locale')) {
@ -326,7 +326,7 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface {
$langcodes = $langcode_cache->data;
}
if (empty($langcodes)) {
$langcodes = array();
$langcodes = [];
// Collect languages included with CKEditor based on file listing.
$files = scandir('core/assets/vendor/ckeditor/lang');
foreach ($files as $file) {
@ -341,7 +341,7 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface {
// Get language mapping if available to map to Drupal language codes.
// This is configurable in the user interface and not expensive to get, so
// we don't include it in the cached language list.
$language_mappings = $this->moduleHandler->moduleExists('language') ? language_get_browser_drupal_langcode_mappings() : array();
$language_mappings = $this->moduleHandler->moduleExists('language') ? language_get_browser_drupal_langcode_mappings() : [];
foreach ($langcodes as $langcode) {
// If this language code is available in a Drupal mapping, use that to
// compute a possibility for matching from the Drupal langcode to the
@ -363,9 +363,9 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface {
* {@inheritdoc}
*/
public function getLibraries(Editor $editor) {
$libraries = array(
$libraries = [
'ckeditor/drupal.ckeditor',
);
];
// Get the required libraries for any enabled plugins.
$enabled_plugins = array_keys($this->ckeditorPluginManager->getEnabledPluginFiles($editor));
@ -389,7 +389,7 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface {
* An array containing the "toolbar" configuration.
*/
public function buildToolbarJSSetting(Editor $editor) {
$toolbar = array();
$toolbar = [];
$settings = $editor->getSettings();
foreach ($settings['toolbar']['rows'] as $row) {
@ -412,15 +412,15 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface {
* An array containing the "contentsCss" configuration.
*/
public function buildContentsCssJSSetting(Editor $editor) {
$css = array(
$css = [
drupal_get_path('module', 'ckeditor') . '/css/ckeditor-iframe.css',
drupal_get_path('module', 'system') . '/css/components/align.module.css',
);
];
$this->moduleHandler->alter('ckeditor_css', $css, $editor);
// Get a list of all enabled plugins' iframe instance CSS files.
$plugins_css = array_reduce($this->ckeditorPluginManager->getCssFiles($editor), function($result, $item) {
return array_merge($result, array_values($item));
}, array());
}, []);
$css = array_merge($css, $plugins_css);
$css = array_merge($css, _ckeditor_theme_css());
$css = array_map('file_create_url', $css);

View file

@ -20,7 +20,7 @@ class CKEditorAdminTest extends WebTestBase {
*
* @var array
*/
public static $modules = array('filter', 'editor', 'ckeditor');
public static $modules = ['filter', 'editor', 'ckeditor'];
/**
* A user with the 'administer filters' permission.
@ -33,22 +33,22 @@ class CKEditorAdminTest extends WebTestBase {
parent::setUp();
// Create text format.
$filtered_html_format = FilterFormat::create(array(
$filtered_html_format = FilterFormat::create([
'format' => 'filtered_html',
'name' => 'Filtered HTML',
'weight' => 0,
'filters' => array(),
));
'filters' => [],
]);
$filtered_html_format->save();
// Create admin user.
$this->adminUser = $this->drupalCreateUser(array('administer filters'));
$this->adminUser = $this->drupalCreateUser(['administer filters']);
}
/**
* Tests configuring a text editor for an existing text format.
*/
function testExistingFormat() {
public function testExistingFormat() {
$ckeditor = $this->container->get('plugin.manager.editor')->createInstance('ckeditor');
$this->drupalLogin($this->adminUser);
@ -70,43 +70,43 @@ class CKEditorAdminTest extends WebTestBase {
$this->assertTrue(((string) $options[0]['selected']) === 'selected', 'Option 1 ("None") is selected.');
// Select the "CKEditor" editor and click the "Save configuration" button.
$edit = array(
$edit = [
'editor[editor]' => 'ckeditor',
);
];
$this->drupalPostForm(NULL, $edit, t('Save configuration'));
$this->assertRaw(t('You must configure the selected text editor.'));
// Ensure the CKEditor editor returns the expected default settings.
$expected_default_settings = array(
'toolbar' => array(
'rows' => array(
$expected_default_settings = [
'toolbar' => [
'rows' => [
// Button groups
array(
array(
[
[
'name' => 'Formatting',
'items' => array('Bold', 'Italic',),
),
array(
'items' => ['Bold', 'Italic'],
],
[
'name' => 'Links',
'items' => array('DrupalLink', 'DrupalUnlink',),
),
array(
'items' => ['DrupalLink', 'DrupalUnlink'],
],
[
'name' => 'Lists',
'items' => array('BulletedList', 'NumberedList',),
),
array(
'items' => ['BulletedList', 'NumberedList'],
],
[
'name' => 'Media',
'items' => array('Blockquote', 'DrupalImage',),
),
array(
'items' => ['Blockquote', 'DrupalImage'],
],
[
'name' => 'Tools',
'items' => array('Source',),
),
),
),
),
'items' => ['Source'],
],
],
],
],
'plugins' => ['language' => ['language_list' => 'un']],
);
];
$this->assertIdentical($this->castSafeStrings($ckeditor->getDefaultSettings()), $expected_default_settings);
// Keep the "CKEditor" editor selected and click the "Configure" button.
@ -115,11 +115,11 @@ class CKEditorAdminTest extends WebTestBase {
$this->assertFalse($editor, 'No Editor config entity exists yet.');
// Ensure that drupalSettings is correct.
$ckeditor_settings_toolbar = array(
$ckeditor_settings_toolbar = [
'#theme' => 'ckeditor_settings_toolbar',
'#editor' => Editor::create(['editor' => 'ckeditor']),
'#plugins' => $this->container->get('plugin.manager.ckeditor.plugin')->getButtons(),
);
];
$this->assertEqual(
$this->drupalSettings['ckeditor']['toolbarAdmin'],
$this->container->get('renderer')->renderPlain($ckeditor_settings_toolbar),
@ -148,9 +148,9 @@ class CKEditorAdminTest extends WebTestBase {
// Configure the Styles plugin, and ensure the updated settings are saved.
$this->drupalGet('admin/config/content/formats/manage/filtered_html');
$edit = array(
$edit = [
'editor[settings][plugins][stylescombo][styles]' => "h1.title|Title\np.callout|Callout\n\n",
);
];
$this->drupalPostForm(NULL, $edit, t('Save configuration'));
$expected_settings['plugins']['stylescombo']['styles'] = "h1.title|Title\np.callout|Callout\n\n";
$editor = Editor::load('filtered_html');
@ -161,13 +161,13 @@ class CKEditorAdminTest extends WebTestBase {
// done via drag and drop, but here we can only emulate the end result of
// that interaction). Test multiple toolbar rows and a divider within a row.
$this->drupalGet('admin/config/content/formats/manage/filtered_html');
$expected_settings['toolbar']['rows'][0][] = array(
$expected_settings['toolbar']['rows'][0][] = [
'name' => 'Action history',
'items' => array('Undo', '|', 'Redo', 'JustifyCenter'),
);
$edit = array(
'items' => ['Undo', '|', 'Redo', 'JustifyCenter'],
];
$edit = [
'editor[settings][toolbar][button_groups]' => json_encode($expected_settings['toolbar']['rows']),
);
];
$this->drupalPostForm(NULL, $edit, t('Save configuration'));
$editor = Editor::load('filtered_html');
$this->assertTrue($editor instanceof Editor, 'An Editor config entity exists.');
@ -191,7 +191,7 @@ class CKEditorAdminTest extends WebTestBase {
// Now enable the ckeditor_test module, which provides one configurable
// CKEditor plugin — this should not affect the Editor config entity.
\Drupal::service('module_installer')->install(array('ckeditor_test'));
\Drupal::service('module_installer')->install(['ckeditor_test']);
$this->resetAll();
$this->container->get('plugin.manager.ckeditor.plugin')->clearCachedDefinitions();
$this->drupalGet('admin/config/content/formats/manage/filtered_html');
@ -203,9 +203,9 @@ class CKEditorAdminTest extends WebTestBase {
// Finally, check the "Ultra llama mode" checkbox.
$this->drupalGet('admin/config/content/formats/manage/filtered_html');
$edit = array(
$edit = [
'editor[settings][plugins][llama_contextual_and_button][ultra_llama_mode]' => '1',
);
];
$this->drupalPostForm(NULL, $edit, t('Save configuration'));
$this->drupalGet('admin/config/content/formats/manage/filtered_html');
$ultra_llama_mode_checkbox = $this->xpath('//input[@type="checkbox" and @name="editor[settings][plugins][llama_contextual_and_button][ultra_llama_mode]" and @checked="checked"]');
@ -222,7 +222,7 @@ class CKEditorAdminTest extends WebTestBase {
* This test only needs to ensure that the basics of the CKEditor
* configuration form work; details are tested in testExistingFormat().
*/
function testNewFormat() {
public function testNewFormat() {
$this->drupalLogin($this->adminUser);
$this->drupalGet('admin/config/content/formats/add');
@ -239,11 +239,11 @@ class CKEditorAdminTest extends WebTestBase {
// Name our fancy new text format, select the "CKEditor" editor and click
// the "Configure" button.
$edit = array(
$edit = [
'name' => 'My amazing text format',
'format' => 'amazing_format',
'editor[editor]' => 'ckeditor',
);
];
$this->drupalPostAjaxForm(NULL, $edit, 'editor_configure');
$filter_format = FilterFormat::load('amazing_format');
$this->assertFalse($filter_format, 'No FilterFormat config entity exists yet.');

View file

@ -18,7 +18,7 @@ class CKEditorLoadingTest extends WebTestBase {
*
* @var array
*/
public static $modules = array('filter', 'editor', 'ckeditor', 'node');
public static $modules = ['filter', 'editor', 'ckeditor', 'node'];
/**
* An untrusted user with access to only the 'plain_text' format.
@ -38,12 +38,12 @@ class CKEditorLoadingTest extends WebTestBase {
parent::setUp();
// Create text format, associate CKEditor.
$filtered_html_format = FilterFormat::create(array(
$filtered_html_format = FilterFormat::create([
'format' => 'filtered_html',
'name' => 'Filtered HTML',
'weight' => 0,
'filters' => array(),
));
'filters' => [],
]);
$filtered_html_format->save();
$editor = Editor::create([
'format' => 'filtered_html',
@ -53,28 +53,28 @@ class CKEditorLoadingTest extends WebTestBase {
// Create a second format without an associated editor so a drop down select
// list is created when selecting formats.
$full_html_format = FilterFormat::create(array(
$full_html_format = FilterFormat::create([
'format' => 'full_html',
'name' => 'Full HTML',
'weight' => 1,
'filters' => array(),
));
'filters' => [],
]);
$full_html_format->save();
// Create node type.
$this->drupalCreateContentType(array(
$this->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
));
]);
$this->untrustedUser = $this->drupalCreateUser(array('create article content', 'edit any article content'));
$this->normalUser = $this->drupalCreateUser(array('create article content', 'edit any article content', 'use text format filtered_html', 'use text format full_html'));
$this->untrustedUser = $this->drupalCreateUser(['create article content', 'edit any article content']);
$this->normalUser = $this->drupalCreateUser(['create article content', 'edit any article content', 'use text format filtered_html', 'use text format full_html']);
}
/**
* Tests loading of CKEditor CSS, JS and JS settings.
*/
function testLoading() {
public function testLoading() {
// The untrusted user:
// - has access to 1 text format (plain_text);
// - doesn't have access to the filtered_html text format, so: no text editor.
@ -101,13 +101,13 @@ class CKEditorLoadingTest extends WebTestBase {
list($settings, $editor_settings_present, $editor_js_present, $body, $format_selector) = $this->getThingsToCheck();
$ckeditor_plugin = $this->container->get('plugin.manager.editor')->createInstance('ckeditor');
$editor = Editor::load('filtered_html');
$expected = array('formats' => array('filtered_html' => array(
$expected = ['formats' => ['filtered_html' => [
'format' => 'filtered_html',
'editor' => 'ckeditor',
'editorSettings' => $this->castSafeStrings($ckeditor_plugin->getJSSettings($editor)),
'editorSupportsContentFiltering' => TRUE,
'isXssSafe' => FALSE,
)));
]]];
$this->assertTrue($editor_settings_present, "Text Editor module's JavaScript settings are on the page.");
$this->assertIdentical($expected, $this->castSafeStrings($settings['editor']), "Text Editor module's JavaScript settings on the page are correct.");
$this->assertTrue($editor_js_present, 'Text Editor JavaScript is present.');
@ -122,7 +122,7 @@ class CKEditorLoadingTest extends WebTestBase {
// NOTE: the tests in CKEditorTest already ensure that changing the
// configuration also results in modified CKEditor configuration, so we
// don't test that here.
\Drupal::service('module_installer')->install(array('ckeditor_test'));
\Drupal::service('module_installer')->install(['ckeditor_test']);
$this->container->get('plugin.manager.ckeditor.plugin')->clearCachedDefinitions();
$editor_settings = $editor->getSettings();
$editor_settings['toolbar']['rows'][0][0]['items'][] = 'Llama';
@ -130,15 +130,15 @@ class CKEditorLoadingTest extends WebTestBase {
$editor->save();
$this->drupalGet('node/add/article');
list($settings, $editor_settings_present, $editor_js_present, $body, $format_selector) = $this->getThingsToCheck();
$expected = array(
'formats' => array(
'filtered_html' => array(
$expected = [
'formats' => [
'filtered_html' => [
'format' => 'filtered_html',
'editor' => 'ckeditor',
'editorSettings' => $this->castSafeStrings($ckeditor_plugin->getJSSettings($editor)),
'editorSupportsContentFiltering' => TRUE,
'isXssSafe' => FALSE,
)));
]]];
$this->assertTrue($editor_settings_present, "Text Editor module's JavaScript settings are on the page.");
$this->assertIdentical($expected, $this->castSafeStrings($settings['editor']), "Text Editor module's JavaScript settings on the page are correct.");
$this->assertTrue($editor_js_present, 'Text Editor JavaScript is present.');
@ -158,7 +158,7 @@ class CKEditorLoadingTest extends WebTestBase {
/**
* Tests presence of essential configuration even without Internal's buttons.
*/
protected function testLoadingWithoutInternalButtons() {
public function testLoadingWithoutInternalButtons() {
// Change the CKEditor text editor configuration to only have link buttons.
// This means:
// - 0 buttons are from \Drupal\ckeditor\Plugin\CKEditorPlugin\Internal
@ -197,11 +197,11 @@ class CKEditorLoadingTest extends WebTestBase {
/**
* Tests loading of theme's CKEditor stylesheets defined in the .info file.
*/
function testExternalStylesheets() {
public function testExternalStylesheets() {
$theme_handler = \Drupal::service('theme_handler');
// Case 1: Install theme which has an absolute external CSS URL.
$theme_handler->install(['test_ckeditor_stylesheets_external']);
$theme_handler->setDefault('test_ckeditor_stylesheets_external');
$this->config('system.theme')->set('default', 'test_ckeditor_stylesheets_external')->save();
$expected = [
'https://fonts.googleapis.com/css?family=Open+Sans',
];
@ -209,7 +209,7 @@ class CKEditorLoadingTest extends WebTestBase {
// Case 2: Install theme which has an external protocol-relative CSS URL.
$theme_handler->install(['test_ckeditor_stylesheets_protocol_relative']);
$theme_handler->setDefault('test_ckeditor_stylesheets_protocol_relative');
$this->config('system.theme')->set('default', 'test_ckeditor_stylesheets_protocol_relative')->save();
$expected = [
'//fonts.googleapis.com/css?family=Open+Sans',
];
@ -217,7 +217,7 @@ class CKEditorLoadingTest extends WebTestBase {
// Case 3: Install theme which has a relative CSS URL.
$theme_handler->install(['test_ckeditor_stylesheets_relative']);
$theme_handler->setDefault('test_ckeditor_stylesheets_relative');
$this->config('system.theme')->set('default', 'test_ckeditor_stylesheets_relative')->save();
$expected = [
'core/modules/system/tests/themes/test_ckeditor_stylesheets_relative/css/yokotsoko.css',
];
@ -226,7 +226,7 @@ class CKEditorLoadingTest extends WebTestBase {
protected function getThingsToCheck() {
$settings = $this->getDrupalSettings();
return array(
return [
// JavaScript settings.
$settings,
// Editor.module's JS settings present.
@ -239,7 +239,7 @@ class CKEditorLoadingTest extends WebTestBase {
$this->xpath('//textarea[@id="edit-body-0-value"]'),
// Format selector.
$this->xpath('//select[contains(@class, "filter-list")]'),
);
];
}
}

View file

@ -59,7 +59,7 @@ class CKEditorStylesComboAdminTest extends WebTestBase {
/**
* Tests StylesCombo settings for an existing text format.
*/
function testExistingFormat() {
public function testExistingFormat() {
$ckeditor = $this->container->get('plugin.manager.editor')->createInstance('ckeditor');
$default_settings = $ckeditor->getDefaultSettings();

View file

@ -0,0 +1,5 @@
ajax_css:
js:
js/ajax-css.js: {}
dependencies:
- ckeditor/drupal.ckeditor

View file

@ -0,0 +1,7 @@
ckeditor_test.ajax_css:
path: '/ckeditor_test/ajax_css'
defaults:
_title: 'AJAX CSS Test'
_form: '\Drupal\ckeditor_test\Form\AjaxCssForm'
requirements:
_access: 'TRUE'

View file

@ -0,0 +1,3 @@
body {
color: red;
}

View file

@ -0,0 +1,24 @@
/**
* @file
* Contains client-side code for testing CSS delivered to CKEditor via AJAX.
*/
(function (Drupal, ckeditor, editorSettings, $) {
'use strict';
Drupal.behaviors.ajaxCssForm = {
attach: function (context) {
// Initialize an inline CKEditor on the #edit-inline element if it
// isn't editable already.
$(context)
.find('#edit-inline')
.not('[contenteditable]')
.each(function () {
ckeditor.attachInlineEditor(this, editorSettings.formats.test_format);
});
}
};
})(Drupal, Drupal.editors.ckeditor, drupalSettings.editor, jQuery);

View file

@ -0,0 +1,111 @@
<?php
namespace Drupal\ckeditor_test\Form;
use Drupal\ckeditor\Ajax\AddStyleSheetCommand;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* A form for testing delivery of CSS to CKEditor via AJAX.
*/
class AjaxCssForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'ckeditor_test_ajax_css_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
// Create an inline and iframe CKEditor instance so we can test against
// both.
$form['inline'] = [
'#type' => 'container',
'#attached' => [
'library' => [
'ckeditor_test/ajax_css',
],
],
'#children' => $this->t('Here be dragons.'),
];
$form['iframe'] = [
'#type' => 'text_format',
'#default_value' => $this->t('Here be llamas.'),
];
// A pair of buttons to trigger the AJAX events.
$form['actions'] = [
'css_inline' => [
'#type' => 'submit',
'#value' => $this->t('Add CSS to inline CKEditor instance'),
'#ajax' => [
'callback' => [$this, 'addCssInline'],
],
],
'css_frame' => [
'#type' => 'submit',
'#value' => $this->t('Add CSS to iframe CKEditor instance'),
'#ajax' => [
'callback' => [$this, 'addCssIframe'],
],
],
'#type' => 'actions',
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Nothing to do here.
}
/**
* Generates an AJAX response to add CSS to a CKEditor Text Editor instance.
*
* @param string $editor_id
* The Text Editor instance ID.
*
* @return \Drupal\Core\Ajax\AjaxResponse
* An AJAX response.
*/
protected function generateResponse($editor_id) {
// Build a URL to the style sheet that will be added.
$url = drupal_get_path('module', 'ckeditor_test') . '/css/test.css';
$url = file_create_url($url);
$url = file_url_transform_relative($url);
$response = new AjaxResponse();
return $response
->addCommand(new AddStyleSheetCommand($editor_id, [$url]));
}
/**
* Handles the AJAX request to add CSS to the inline editor.
*
* @return \Drupal\Core\Ajax\AjaxResponse
* An AJAX response.
*/
public function addCssInline() {
return $this->generateResponse('edit-inline');
}
/**
* Handles the AJAX request to add CSS to the iframe editor.
*
* @return \Drupal\Core\Ajax\AjaxResponse
* An AJAX response.
*/
public function addCssIframe() {
return $this->generateResponse('edit-iframe-value');
}
}

View file

@ -18,7 +18,7 @@ class CKEditorPluginManagerTest extends KernelTestBase {
*
* @var array
*/
public static $modules = array('system', 'user', 'filter', 'editor', 'ckeditor');
public static $modules = ['system', 'user', 'filter', 'editor', 'ckeditor'];
/**
* The manager for "CKEditor plugin" plugins.
@ -33,12 +33,12 @@ class CKEditorPluginManagerTest extends KernelTestBase {
// Install the Filter module.
// Create text format, associate CKEditor.
$filtered_html_format = FilterFormat::create(array(
$filtered_html_format = FilterFormat::create([
'format' => 'filtered_html',
'name' => 'Filtered HTML',
'weight' => 0,
'filters' => array(),
));
'filters' => [],
]);
$filtered_html_format->save();
$editor = Editor::create([
'format' => 'filtered_html',
@ -50,34 +50,34 @@ class CKEditorPluginManagerTest extends KernelTestBase {
/**
* Tests the enabling of plugins.
*/
function testEnabledPlugins() {
public function testEnabledPlugins() {
$this->manager = $this->container->get('plugin.manager.ckeditor.plugin');
$editor = Editor::load('filtered_html');
// Case 1: no CKEditor plugins.
$definitions = array_keys($this->manager->getDefinitions());
sort($definitions);
$this->assertIdentical(array('drupalimage', 'drupalimagecaption', 'drupallink', 'internal', 'language', 'stylescombo'), $definitions, 'No CKEditor plugins found besides the built-in ones.');
$enabled_plugins = array(
$this->assertIdentical(['drupalimage', 'drupalimagecaption', 'drupallink', 'internal', 'language', 'stylescombo'], $definitions, 'No CKEditor plugins found besides the built-in ones.');
$enabled_plugins = [
'drupalimage' => drupal_get_path('module', 'ckeditor') . '/js/plugins/drupalimage/plugin.js',
'drupallink' => drupal_get_path('module', 'ckeditor') . '/js/plugins/drupallink/plugin.js',
);
];
$this->assertIdentical($enabled_plugins, $this->manager->getEnabledPluginFiles($editor), 'Only built-in plugins are enabled.');
$this->assertIdentical(array('internal' => NULL) + $enabled_plugins, $this->manager->getEnabledPluginFiles($editor, TRUE), 'Only the "internal" plugin is enabled.');
$this->assertIdentical(['internal' => NULL] + $enabled_plugins, $this->manager->getEnabledPluginFiles($editor, TRUE), 'Only the "internal" plugin is enabled.');
// Enable the CKEditor Test module, which has the Llama plugin (plus four
// variations of it, to cover all possible ways a plugin can be enabled) and
// clear the editor manager's cache so it is picked up.
$this->enableModules(array('ckeditor_test'));
$this->enableModules(['ckeditor_test']);
$this->manager = $this->container->get('plugin.manager.ckeditor.plugin');
$this->manager->clearCachedDefinitions();
// Case 2: CKEditor plugins are available.
$plugin_ids = array_keys($this->manager->getDefinitions());
sort($plugin_ids);
$this->assertIdentical(array('drupalimage', 'drupalimagecaption', 'drupallink', 'internal', 'language', 'llama', 'llama_button', 'llama_contextual', 'llama_contextual_and_button', 'llama_css', 'stylescombo'), $plugin_ids, 'Additional CKEditor plugins found.');
$this->assertIdentical(['drupalimage', 'drupalimagecaption', 'drupallink', 'internal', 'language', 'llama', 'llama_button', 'llama_contextual', 'llama_contextual_and_button', 'llama_css', 'stylescombo'], $plugin_ids, 'Additional CKEditor plugins found.');
$this->assertIdentical($enabled_plugins, $this->manager->getEnabledPluginFiles($editor), 'Only the internal plugins are enabled.');
$this->assertIdentical(array('internal' => NULL) + $enabled_plugins, $this->manager->getEnabledPluginFiles($editor, TRUE), 'Only the "internal" plugin is enabled.');
$this->assertIdentical(['internal' => NULL] + $enabled_plugins, $this->manager->getEnabledPluginFiles($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
@ -100,48 +100,48 @@ class CKEditorPluginManagerTest extends KernelTestBase {
$settings['toolbar']['rows'][0][0]['items'][] = 'Llama';
$editor->setSettings($settings);
$editor->save();
$file = array();
$file = [];
$file['b'] = drupal_get_path('module', 'ckeditor_test') . '/js/llama_button.js';
$file['c'] = drupal_get_path('module', 'ckeditor_test') . '/js/llama_contextual.js';
$file['cb'] = drupal_get_path('module', 'ckeditor_test') . '/js/llama_contextual_and_button.js';
$file['css'] = drupal_get_path('module', 'ckeditor_test') . '/js/llama_css.js';
$expected = $enabled_plugins + array('llama_button' => $file['b'], 'llama_contextual_and_button' => $file['cb']);
$expected = $enabled_plugins + ['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(['internal' => NULL] + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LlamaButton and LlamaContextualAndButton plugins are enabled.');
$settings['toolbar'] = $original_toolbar;
$settings['toolbar']['rows'][0][0]['items'][] = 'Strike';
$editor->setSettings($settings);
$editor->save();
$expected = $enabled_plugins + array('llama_contextual' => $file['c'], 'llama_contextual_and_button' => $file['cb']);
$expected = $enabled_plugins + ['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(['internal' => NULL] + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LlamaContextual and LlamaContextualAndButton plugins are enabled.');
$settings['toolbar']['rows'][0][0]['items'][] = 'Llama';
$editor->setSettings($settings);
$editor->save();
$expected = $enabled_plugins + array('llama_button' => $file['b'], 'llama_contextual' => $file['c'], 'llama_contextual_and_button' => $file['cb']);
$expected = $enabled_plugins + ['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(['internal' => NULL] + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LLamaButton, LlamaContextual and LlamaContextualAndButton plugins are enabled.');
$settings['toolbar']['rows'][0][0]['items'][] = 'LlamaCSS';
$editor->setSettings($settings);
$editor->save();
$expected = $enabled_plugins + array('llama_button' => $file['b'], 'llama_contextual' => $file['c'], 'llama_contextual_and_button' => $file['cb'], 'llama_css' => $file['css']);
$expected = $enabled_plugins + ['llama_button' => $file['b'], 'llama_contextual' => $file['c'], 'llama_contextual_and_button' => $file['cb'], 'llama_css' => $file['css']];
$this->assertIdentical($expected, $this->manager->getEnabledPluginFiles($editor), 'The LlamaButton, LlamaContextual, LlamaContextualAndButton and LlamaCSS plugins are enabled.');
$this->assertIdentical(array('internal' => NULL) + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LLamaButton, LlamaContextual, LlamaContextualAndButton and LlamaCSS plugins are enabled.');
$this->assertIdentical(['internal' => NULL] + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LLamaButton, LlamaContextual, LlamaContextualAndButton and LlamaCSS plugins are enabled.');
}
/**
* Tests the iframe instance CSS files of plugins.
*/
function testCssFiles() {
public function testCssFiles() {
$this->manager = $this->container->get('plugin.manager.ckeditor.plugin');
$editor = Editor::load('filtered_html');
// Case 1: no CKEditor iframe instance CSS file.
$this->assertIdentical(array(), $this->manager->getCssFiles($editor), 'No iframe instance CSS file found.');
$this->assertIdentical([], $this->manager->getCssFiles($editor), 'No iframe instance CSS file found.');
// Enable the CKEditor Test module, which has the LlamaCss plugin and
// clear the editor manager's cache so it is picked up.
$this->enableModules(array('ckeditor_test'));
$this->enableModules(['ckeditor_test']);
$this->manager = $this->container->get('plugin.manager.ckeditor.plugin');
$settings = $editor->getSettings();
// LlamaCss: automatically enabled by adding its 'LlamaCSS' button.
@ -150,9 +150,9 @@ class CKEditorPluginManagerTest extends KernelTestBase {
$editor->save();
// Case 2: CKEditor iframe instance CSS file.
$expected = array(
'llama_css' => array(drupal_get_path('module', 'ckeditor_test') . '/css/llama.css')
);
$expected = [
'llama_css' => [drupal_get_path('module', 'ckeditor_test') . '/css/llama.css']
];
$this->assertIdentical($expected, $this->manager->getCssFiles($editor), 'Iframe instance CSS file found.');
}

View file

@ -19,7 +19,7 @@ class CKEditorTest extends KernelTestBase {
*
* @var array
*/
public static $modules = array('system', 'user', 'filter', 'editor', 'ckeditor', 'filter_test');
public static $modules = ['system', 'user', 'filter', 'editor', 'ckeditor', 'filter_test'];
/**
* An instance of the "CKEditor" text editor plugin.
@ -41,19 +41,19 @@ class CKEditorTest extends KernelTestBase {
// Install the Filter module.
// Create text format, associate CKEditor.
$filtered_html_format = FilterFormat::create(array(
$filtered_html_format = FilterFormat::create([
'format' => 'filtered_html',
'name' => 'Filtered HTML',
'weight' => 0,
'filters' => array(
'filter_html' => array(
'filters' => [
'filter_html' => [
'status' => 1,
'settings' => array(
'settings' => [
'allowed_html' => '<h2 id> <h3> <h4> <h5> <h6> <p> <br> <strong> <a href hreflang>',
)
),
),
));
]
],
],
]);
$filtered_html_format->save();
$editor = Editor::create([
'format' => 'filtered_html',
@ -68,11 +68,11 @@ class CKEditorTest extends KernelTestBase {
/**
* Tests CKEditor::getJSSettings().
*/
function testGetJSSettings() {
public function testGetJSSettings() {
$editor = Editor::load('filtered_html');
// Default toolbar.
$expected_config = $this->getDefaultInternalConfig() + array(
$expected_config = $this->getDefaultInternalConfig() + [
'drupalImage_dialogTitleAdd' => 'Insert Image',
'drupalImage_dialogTitleEdit' => 'Edit Image',
'drupalLink_dialogTitleAdd' => 'Add Link',
@ -84,11 +84,11 @@ class CKEditorTest extends KernelTestBase {
'extraPlugins' => 'drupalimage,drupallink',
'language' => 'en',
'stylesSet' => FALSE,
'drupalExternalPlugins' => array(
'drupalExternalPlugins' => [
'drupalimage' => file_url_transform_relative(file_create_url('core/modules/ckeditor/js/plugins/drupalimage/plugin.js')),
'drupallink' => file_url_transform_relative(file_create_url('core/modules/ckeditor/js/plugins/drupallink/plugin.js')),
),
);
],
];
$expected_config = $this->castSafeStrings($expected_config);
ksort($expected_config);
ksort($expected_config['allowedContent']);
@ -96,7 +96,7 @@ class CKEditorTest extends KernelTestBase {
// Customize the configuration: add button, have two contextually enabled
// buttons, and configure a CKEditor plugin setting.
$this->enableModules(array('ckeditor_test'));
$this->enableModules(['ckeditor_test']);
$this->container->get('plugin.manager.editor')->clearCachedDefinitions();
$this->ckeditor = $this->container->get('plugin.manager.editor')->createInstance('ckeditor');
$this->container->get('plugin.manager.ckeditor.plugin')->clearCachedDefinitions();
@ -121,16 +121,16 @@ class CKEditorTest extends KernelTestBase {
$format->filters('filter_html')->settings['allowed_html'] .= '<pre class> <h1> <blockquote class="*"> <address class="foo bar-* *">';
$format->save();
$expected_config['allowedContent']['pre'] = array('attributes' => 'class', 'styles' => FALSE, 'classes' => TRUE);
$expected_config['allowedContent']['h1'] = array('attributes' => FALSE, 'styles' => FALSE, 'classes' => FALSE);
$expected_config['allowedContent']['blockquote'] = array('attributes' => 'class', 'styles' => FALSE, 'classes' => TRUE);
$expected_config['allowedContent']['address'] = array('attributes' => 'class', 'styles' => FALSE, 'classes' => 'foo,bar-*');
$expected_config['allowedContent']['pre'] = ['attributes' => 'class', 'styles' => FALSE, 'classes' => TRUE];
$expected_config['allowedContent']['h1'] = ['attributes' => FALSE, 'styles' => FALSE, 'classes' => FALSE];
$expected_config['allowedContent']['blockquote'] = ['attributes' => 'class', 'styles' => FALSE, 'classes' => TRUE];
$expected_config['allowedContent']['address'] = ['attributes' => 'class', 'styles' => FALSE, 'classes' => 'foo,bar-*'];
$expected_config['format_tags'] = 'p;h1;h2;h3;h4;h5;h6;pre';
ksort($expected_config['allowedContent']);
$this->assertIdentical($expected_config, $this->castSafeStrings($this->ckeditor->getJSSettings($editor)), 'Generated JS settings are correct for customized configuration.');
// Disable the filter_html filter: allow *all *tags.
$format->setFilterConfig('filter_html', array('status' => 0));
$format->setFilterConfig('filter_html', ['status' => 0]);
$format->save();
$expected_config['allowedContent'] = TRUE;
@ -139,73 +139,73 @@ class CKEditorTest extends KernelTestBase {
$this->assertIdentical($expected_config, $this->castSafeStrings($this->ckeditor->getJSSettings($editor)), 'Generated JS settings are correct for customized configuration.');
// Enable the filter_test_restrict_tags_and_attributes filter.
$format->setFilterConfig('filter_test_restrict_tags_and_attributes', array(
$format->setFilterConfig('filter_test_restrict_tags_and_attributes', [
'status' => 1,
'settings' => array(
'restrictions' => array(
'allowed' => array(
'settings' => [
'restrictions' => [
'allowed' => [
'p' => TRUE,
'a' => array(
'a' => [
'href' => TRUE,
'rel' => array('nofollow' => TRUE),
'class' => array('external' => TRUE),
'target' => array('_blank' => FALSE),
),
'span' => array(
'class' => array('dodo' => FALSE),
'property' => array('dc:*' => TRUE),
'rel' => array('foaf:*' => FALSE),
'style' => array('underline' => FALSE, 'color' => FALSE, 'font-size' => TRUE),
),
'*' => array(
'rel' => ['nofollow' => TRUE],
'class' => ['external' => TRUE],
'target' => ['_blank' => FALSE],
],
'span' => [
'class' => ['dodo' => FALSE],
'property' => ['dc:*' => TRUE],
'rel' => ['foaf:*' => FALSE],
'style' => ['underline' => FALSE, 'color' => FALSE, 'font-size' => TRUE],
],
'*' => [
'style' => FALSE,
'on*' => FALSE,
'class' => array('is-a-hipster-llama' => TRUE, 'and-more' => TRUE),
'class' => ['is-a-hipster-llama' => TRUE, 'and-more' => TRUE],
'data-*' => TRUE,
),
],
'del' => FALSE,
),
),
),
));
],
],
],
]);
$format->save();
$expected_config['allowedContent'] = array(
'p' => array(
$expected_config['allowedContent'] = [
'p' => [
'attributes' => TRUE,
'styles' => FALSE,
'classes' => 'is-a-hipster-llama,and-more',
),
'a' => array(
],
'a' => [
'attributes' => 'href,rel,class,target',
'styles' => FALSE,
'classes' => 'external',
),
'span' => array(
],
'span' => [
'attributes' => 'class,property,rel,style',
'styles' => 'font-size',
'classes' => FALSE,
),
'*' => array(
],
'*' => [
'attributes' => 'class,data-*',
'styles' => FALSE,
'classes' => 'is-a-hipster-llama,and-more',
),
'del' => array(
],
'del' => [
'attributes' => FALSE,
'styles' => FALSE,
'classes' => FALSE,
),
);
$expected_config['disallowedContent'] = array(
'span' => array(
],
];
$expected_config['disallowedContent'] = [
'span' => [
'styles' => 'underline,color',
'classes' => 'dodo',
),
'*' => array(
],
'*' => [
'attributes' => 'on*',
),
);
],
];
$expected_config['format_tags'] = 'p';
ksort($expected_config);
ksort($expected_config['allowedContent']);
@ -216,7 +216,7 @@ class CKEditorTest extends KernelTestBase {
/**
* Tests CKEditor::buildToolbarJSSetting().
*/
function testBuildToolbarJSSetting() {
public function testBuildToolbarJSSetting() {
$editor = Editor::load('filtered_html');
// Default toolbar.
@ -232,7 +232,7 @@ class CKEditorTest extends KernelTestBase {
$this->assertIdentical($expected, $this->castSafeStrings($this->ckeditor->buildToolbarJSSetting($editor)), '"toolbar" configuration part of JS settings built correctly for customized toolbar.');
// Enable the editor_test module, customize further.
$this->enableModules(array('ckeditor_test'));
$this->enableModules(['ckeditor_test']);
$this->container->get('plugin.manager.ckeditor.plugin')->clearCachedDefinitions();
// Override the label of a toolbar component.
$settings['toolbar']['rows'][0][0]['name'] = 'JunkScience';
@ -247,7 +247,7 @@ class CKEditorTest extends KernelTestBase {
/**
* Tests CKEditor::buildContentsCssJSSetting().
*/
function testBuildContentsCssJSSetting() {
public function testBuildContentsCssJSSetting() {
$editor = Editor::load('filtered_html');
// Default toolbar.
@ -255,7 +255,7 @@ class CKEditorTest extends KernelTestBase {
$this->assertIdentical($expected, $this->ckeditor->buildContentsCssJSSetting($editor), '"contentsCss" configuration part of JS settings built correctly for default toolbar.');
// Enable the editor_test module, which implements hook_ckeditor_css_alter().
$this->enableModules(array('ckeditor_test'));
$this->enableModules(['ckeditor_test']);
$expected[] = file_url_transform_relative(file_create_url(drupal_get_path('module', 'ckeditor_test') . '/ckeditor_test.css'));
$this->assertIdentical($expected, $this->ckeditor->buildContentsCssJSSetting($editor), '"contentsCss" configuration part of JS settings built correctly while a hook_ckeditor_css_alter() implementation exists.');
@ -273,7 +273,7 @@ class CKEditorTest extends KernelTestBase {
// Enable the Bartik theme, which specifies a CKEditor stylesheet.
\Drupal::service('theme_handler')->install(['bartik']);
\Drupal::service('theme_handler')->setDefault('bartik');
$this->config('system.theme')->set('default', 'bartik')->save();
$expected[] = file_url_transform_relative(file_create_url('core/themes/bartik/css/base/elements.css'));
$expected[] = file_url_transform_relative(file_create_url('core/themes/bartik/css/components/captions.css'));
$expected[] = file_url_transform_relative(file_create_url('core/themes/bartik/css/components/table.css'));
@ -284,7 +284,7 @@ class CKEditorTest extends KernelTestBase {
/**
* Tests Internal::getConfig().
*/
function testInternalGetConfig() {
public function testInternalGetConfig() {
$editor = Editor::load('filtered_html');
$internal_plugin = $this->container->get('plugin.manager.ckeditor.plugin')->createInstance('internal');
@ -305,7 +305,7 @@ class CKEditorTest extends KernelTestBase {
/**
* Tests StylesCombo::getConfig().
*/
function testStylesComboGetConfig() {
public function testStylesComboGetConfig() {
$editor = Editor::load('filtered_html');
$stylescombo_plugin = $this->container->get('plugin.manager.ckeditor.plugin')->createInstance('stylescombo');
@ -315,7 +315,7 @@ class CKEditorTest extends KernelTestBase {
$settings['plugins']['stylescombo']['styles'] = '';
$editor->setSettings($settings);
$editor->save();
$expected['stylesSet'] = array();
$expected['stylesSet'] = [];
$this->assertIdentical($expected, $stylescombo_plugin->getConfig($editor), '"StylesCombo" plugin configuration built correctly for customized toolbar.');
// Configure the optional "styles" setting in odd ways that shouldn't affect
@ -333,10 +333,10 @@ class CKEditorTest extends KernelTestBase {
$settings['plugins']['stylescombo']['styles'] = "h1.title|Title\np.mAgical.Callout|Callout";
$editor->setSettings($settings);
$editor->save();
$expected['stylesSet'] = array(
array('name' => 'Title', 'element' => 'h1', 'attributes' => array('class' => 'title')),
array('name' => 'Callout', 'element' => 'p', 'attributes' => array('class' => 'mAgical Callout')),
);
$expected['stylesSet'] = [
['name' => 'Title', 'element' => 'h1', 'attributes' => ['class' => 'title']],
['name' => 'Callout', 'element' => 'p', 'attributes' => ['class' => 'mAgical Callout']],
];
$this->assertIdentical($expected, $stylescombo_plugin->getConfig($editor), '"StylesCombo" plugin configuration built correctly for customized toolbar.');
// Same configuration, but now interspersed with nonsense. Should yield the
@ -350,7 +350,7 @@ class CKEditorTest extends KernelTestBase {
$settings['plugins']['stylescombo']['styles'] = " h1 | Title ";
$editor->setSettings($settings);
$editor->save();
$expected['stylesSet'] = array(array('name' => 'Title', 'element' => 'h1'));
$expected['stylesSet'] = [['name' => 'Title', 'element' => 'h1']];
$this->assertIdentical($expected, $stylescombo_plugin->getConfig($editor), '"StylesCombo" plugin configuration built correctly for customized toolbar.');
// Invalid syntax should cause stylesSet to be set to FALSE.
@ -364,10 +364,10 @@ class CKEditorTest extends KernelTestBase {
/**
* Tests language list availability in CKEditor.
*/
function testLanguages() {
public function testLanguages() {
// Get CKEditor supported language codes and spot-check.
$this->enableModules(array('language'));
$this->installConfig(array('language'));
$this->enableModules(['language']);
$this->installConfig(['language']);
$langcodes = $this->ckeditor->getLangcodes();
// Language codes transformed with browser mappings.
@ -389,15 +389,15 @@ class CKEditorTest extends KernelTestBase {
/**
* Tests that CKEditor plugins participate in JS translation.
*/
function testJSTranslation() {
$this->enableModules(array('language', 'locale'));
public function testJSTranslation() {
$this->enableModules(['language', 'locale']);
$this->installSchema('locale', 'locales_source');
$this->installSchema('locale', 'locales_location');
$this->installSchema('locale', 'locales_target');
$editor = Editor::load('filtered_html');
$this->ckeditor->getJSSettings($editor);
$localeStorage = $this->container->get('locale.storage');
$string = $localeStorage->findString(array('source' => 'Edit Link', 'context' => ''));
$string = $localeStorage->findString(['source' => 'Edit Link', 'context' => '']);
$this->assertTrue(!empty($string), 'String from JavaScript file saved.');
// With locale module, CKEditor should not adhere to the language selected.
@ -428,14 +428,14 @@ class CKEditorTest extends KernelTestBase {
}
protected function getDefaultInternalConfig() {
return array(
return [
'customConfig' => '',
'pasteFromWordPromptCleanup' => TRUE,
'resize_dir' => 'vertical',
'justifyClasses' => array('text-align-left', 'text-align-center', 'text-align-right', 'text-align-justify'),
'justifyClasses' => ['text-align-left', 'text-align-center', 'text-align-right', 'text-align-justify'],
'entities' => FALSE,
'disableNativeSpellChecker' => FALSE,
);
];
}
protected function getDefaultAllowedContentConfig() {
@ -454,42 +454,42 @@ class CKEditorTest extends KernelTestBase {
}
protected function getDefaultDisallowedContentConfig() {
return array(
'*' => array('attributes' => 'on*'),
);
return [
'*' => ['attributes' => 'on*'],
];
}
protected function getDefaultToolbarConfig() {
return array(
array(
return [
[
'name' => 'Formatting',
'items' => array('Bold', 'Italic',),
),
array(
'items' => ['Bold', 'Italic'],
],
[
'name' => 'Links',
'items' => array('DrupalLink', 'DrupalUnlink',),
),
array(
'items' => ['DrupalLink', 'DrupalUnlink'],
],
[
'name' => 'Lists',
'items' => array('BulletedList', 'NumberedList',),
),
array(
'items' => ['BulletedList', 'NumberedList'],
],
[
'name' => 'Media',
'items' => array('Blockquote', 'DrupalImage',),
),
array(
'items' => ['Blockquote', 'DrupalImage'],
],
[
'name' => 'Tools',
'items' => array('Source',),
),
'items' => ['Source', ],
],
'/',
);
];
}
protected function getDefaultContentsCssConfig() {
return array(
return [
file_url_transform_relative(file_create_url('core/modules/ckeditor/css/ckeditor-iframe.css')),
file_url_transform_relative(file_create_url('core/modules/system/css/components/align.module.css')),
);
];
}
}

View file

@ -29,28 +29,28 @@ class Llama extends PluginBase implements CKEditorPluginInterface {
/**
* {@inheritdoc}
*/
function getDependencies(Editor $editor) {
return array();
public function getDependencies(Editor $editor) {
return [];
}
/**
* {@inheritdoc}
*/
function getLibraries(Editor $editor) {
return array();
public function getLibraries(Editor $editor) {
return [];
}
/**
* {@inheritdoc}
*/
function isInternal() {
public function isInternal() {
return FALSE;
}
/**
* {@inheritdoc}
*/
function getFile() {
public function getFile() {
return drupal_get_path('module', 'ckeditor_test') . '/js/llama.js';
}
@ -58,7 +58,7 @@ class Llama extends PluginBase implements CKEditorPluginInterface {
* {@inheritdoc}
*/
public function getConfig(Editor $editor) {
return array();
return [];
}
}

View file

@ -17,18 +17,18 @@ class LlamaButton extends Llama implements CKEditorPluginButtonsInterface {
/**
* {@inheritdoc}
*/
function getButtons() {
return array(
'Llama' => array(
public function getButtons() {
return [
'Llama' => [
'label' => t('Insert Llama'),
),
);
],
];
}
/**
* {@inheritdoc}
*/
function getFile() {
public function getFile() {
return drupal_get_path('module', 'ckeditor_test') . '/js/llama_button.js';
}

View file

@ -18,7 +18,7 @@ class LlamaContextual extends Llama implements CKEditorPluginContextualInterface
/**
* {@inheritdoc}
*/
function isEnabled(Editor $editor) {
public function isEnabled(Editor $editor) {
// Automatically enable this plugin if the Underline button is enabled.
$settings = $editor->getSettings();
foreach ($settings['toolbar']['rows'] as $row) {
@ -34,7 +34,7 @@ class LlamaContextual extends Llama implements CKEditorPluginContextualInterface
/**
* {@inheritdoc}
*/
function getFile() {
public function getFile() {
return drupal_get_path('module', 'ckeditor_test') . '/js/llama_contextual.js';
}

View file

@ -22,7 +22,7 @@ class LlamaContextualAndButton extends Llama implements CKEditorPluginContextual
/**
* {@inheritdoc}
*/
function isEnabled(Editor $editor) {
public function isEnabled(Editor $editor) {
// Automatically enable this plugin if the Strike button is enabled.
$settings = $editor->getSettings();
foreach ($settings['toolbar']['rows'] as $row) {
@ -38,37 +38,37 @@ class LlamaContextualAndButton extends Llama implements CKEditorPluginContextual
/**
* {@inheritdoc}
*/
function getButtons() {
return array(
'Llama' => array(
public function getButtons() {
return [
'Llama' => [
'label' => t('Insert Llama'),
),
);
],
];
}
/**
* {@inheritdoc}
*/
function getFile() {
public function getFile() {
return drupal_get_path('module', 'ckeditor_test') . '/js/llama_contextual_and_button.js';
}
/**
* {@inheritdoc}
*/
function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {
public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {
// Defaults.
$config = array('ultra_llama_mode' => FALSE);
$config = ['ultra_llama_mode' => FALSE];
$settings = $editor->getSettings();
if (isset($settings['plugins']['llama_contextual_and_button'])) {
$config = $settings['plugins']['llama_contextual_and_button'];
}
$form['ultra_llama_mode'] = array(
$form['ultra_llama_mode'] = [
'#title' => t('Ultra llama mode'),
'#type' => 'checkbox',
'#default_value' => $config['ultra_llama_mode'],
);
];
return $form;
}

View file

@ -19,27 +19,27 @@ class LlamaCss extends Llama implements CKEditorPluginButtonsInterface, CKEditor
/**
* {@inheritdoc}
*/
function getButtons() {
return array(
'LlamaCSS' => array(
public function getButtons() {
return [
'LlamaCSS' => [
'label' => t('Insert Llama CSS'),
),
);
],
];
}
/**
* {@inheritdoc}
*/
function getCssFiles(Editor $editor) {
return array(
public function getCssFiles(Editor $editor) {
return [
drupal_get_path('module', 'ckeditor_test') . '/css/llama.css'
);
];
}
/**
* {@inheritdoc}
*/
function getFile() {
public function getFile() {
return drupal_get_path('module', 'ckeditor_test') . '/js/llama_css.js';
}

View file

@ -1,11 +1,11 @@
<?php
namespace Drupal\ckeditor\Tests;
namespace Drupal\Tests\ckeditor\Functional;
use Drupal\filter\Entity\FilterFormat;
use Drupal\editor\Entity\Editor;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
use Drupal\Component\Serialization\Json;
/**
@ -13,7 +13,7 @@ use Drupal\Component\Serialization\Json;
*
* @group ckeditor
*/
class CKEditorToolbarButtonTest extends WebTestBase {
class CKEditorToolbarButtonTest extends BrowserTestBase {
/**
* Modules to enable for this test.

View file

@ -0,0 +1,123 @@
<?php
namespace Drupal\Tests\ckeditor\FunctionalJavascript;
use Drupal\editor\Entity\Editor;
use Drupal\filter\Entity\FilterFormat;
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
/**
* Tests delivery of CSS to CKEditor via AJAX.
*
* @group ckeditor
*/
class AjaxCssTest extends JavascriptTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['ckeditor', 'ckeditor_test'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
FilterFormat::create([
'format' => 'test_format',
'name' => $this->randomMachineName(),
])->save();
Editor::create([
'editor' => 'ckeditor',
'format' => 'test_format',
])->save();
user_role_grant_permissions('anonymous', ['use text format test_format']);
}
/**
* Tests adding style sheets dynamically to CKEditor.
*/
public function testCkeditorAjaxAddCss() {
$this->drupalGet('/ckeditor_test/ajax_css');
$session = $this->getSession();
$page = $session->getPage();
$this->waitOnCkeditorInstance('edit-iframe-value');
$this->waitOnCkeditorInstance('edit-inline');
$style_color = 'rgb(255, 0, 0)';
// Add the inline CSS and assert that the style is applied to the main body,
// but not the iframe.
$page->pressButton('Add CSS to inline CKEditor instance');
$result = $page->waitFor(10, function() use ($style_color) {
return ($this->getEditorStyle('edit-inline', 'color') == $style_color)
&& ($this->getEditorStyle('edit-iframe-value', 'color') != $style_color);
});
$this->assertTrue($result);
$session->reload();
$this->waitOnCkeditorInstance('edit-iframe-value');
$this->waitOnCkeditorInstance('edit-inline');
// Add the iframe CSS and assert that the style is applied to the iframe,
// but not the main body.
$page->pressButton('Add CSS to iframe CKEditor instance');
$result = $page->waitFor(10, function() use ($style_color) {
return ($this->getEditorStyle('edit-inline', 'color') != $style_color)
&& ($this->getEditorStyle('edit-iframe-value', 'color') == $style_color);
});
$this->assertTrue($result);
}
/**
* Gets a computed style value for a CKEditor instance.
*
* @param string $instance_id
* The CKEditor instance ID.
* @param string $attribute
* The style attribute.
*
* @return string
* The computed style value.
*/
protected function getEditorStyle($instance_id, $attribute) {
$js = sprintf(
'CKEDITOR.instances["%s"].document.getBody().getComputedStyle("%s")',
$instance_id,
$attribute
);
return $this->getSession()->evaluateScript($js);
}
/**
* Wait for a CKEditor instance to finish loading and initializing.
*
* @param string $instance_id
* The CKEditor instance ID.
* @param int $timeout
* (optional) Timeout in milliseconds, defaults to 10000.
*/
protected function waitOnCkeditorInstance($instance_id, $timeout = 10000) {
$condition = <<<JS
(function() {
return (
typeof CKEDITOR !== 'undefined'
&& typeof CKEDITOR.instances["$instance_id"] !== 'undefined'
&& CKEDITOR.instances["$instance_id"].instanceReady
);
}());
JS;
$this->getSession()->wait($timeout, $condition);
}
}