diff --git a/core/modules/ckeditor5/ckeditor5.api.php b/core/modules/ckeditor5/ckeditor5.api.php index 577b93d13ed34ff7e30c817ef0c0baf5705ff3d2..596094bc76cb65c88e78167c8d3ddbe646e468d0 100644 --- a/core/modules/ckeditor5/ckeditor5.api.php +++ b/core/modules/ckeditor5/ckeditor5.api.php @@ -185,22 +185,6 @@ * @see \Drupal\ckeditor5\Annotation\CKEditor5AspectsOfCKEditor5Plugin * @see \Drupal\ckeditor5\Annotation\DrupalAspectsOfCKEditor5Plugin * - * @section upgrade_path Upgrade path - * - * Modules can provide upgrade paths similar to the built-in upgrade path for - * Drupal core's CKEditor 4 to CKEditor 5, by providing a CKEditor4To5Upgrade - * plugin. This plugin type allows: - * - mapping a CKEditor 4 button to an equivalent CKEditor 5 toolbar item - * - mapping CKEditor 4 plugin settings to equivalent CKEditor 5 plugin - * configuration. - * The supported CKEditor 4 buttons and/or CKEditor 4 plugin settings must be - * specified in the annotation. - * See Drupal core's implementation for an example. - * - * @see \Drupal\ckeditor5\Annotation\CKEditor4To5Upgrade - * @see \Drupal\ckeditor5\Plugin\CKEditor4To5UpgradePluginInterface - * @see \Drupal\ckeditor5\Plugin\CKEditor4To5Upgrade\Core - * * @section public_api Public API * * The CKEditor 5 module provides no public API, other than: @@ -254,24 +238,6 @@ function hook_ckeditor5_plugin_info_alter(array &$plugin_definitions): void { $plugin_definitions['ckeditor5_link'] = new CKEditor5PluginDefinition($link_plugin_definition); } -/** - * Modify the list of available CKEditor 4 to 5 Upgrade plugins. - * - * This hook may be used to modify plugin properties after they have been - * specified by other modules. For example, to override a default upgrade path. - * - * @param array $plugin_definitions - * An array of all the existing plugin definitions, passed by reference. - * - * @see \Drupal\ckeditor5\Plugin\CKEditor4To5UpgradePluginManager - */ -function hook_ckeditor4to5upgrade_plugin_info_alter(array &$plugin_definitions): void { - // Remove core's upgrade path for the "Maximize" button (which is: there is no - // equivalent). This allows a different CKEditor4To5Upgrade plugin to define - // this upgrade path instead. - unset($plugin_definitions['core']['cke4_buttons']['Maximize']); -} - /** * @} End of "addtogroup hooks". */ diff --git a/core/modules/ckeditor5/ckeditor5.services.yml b/core/modules/ckeditor5/ckeditor5.services.yml index be84b87f2eea5e6b1928a0524a12c663308d4964..d4ad5c193867ac895431d645fa471c1eb2b8c67a 100644 --- a/core/modules/ckeditor5/ckeditor5.services.yml +++ b/core/modules/ckeditor5/ckeditor5.services.yml @@ -5,26 +5,14 @@ services: class: Drupal\ckeditor5\Plugin\CKEditor5PluginManager parent: default_plugin_manager Drupal\ckeditor5\Plugin\CKEditor5PluginManagerInterface: '@plugin.manager.ckeditor5.plugin' - # @todo Remove in Drupal 11: https://www.drupal.org/project/ckeditor5/issues/3239012 - plugin.manager.ckeditor4to5upgrade.plugin: - public: false - class: Drupal\ckeditor5\Plugin\CKEditor4To5UpgradePluginManager - parent: default_plugin_manager ckeditor5.smart_default_settings: class: Drupal\ckeditor5\SmartDefaultSettings arguments: - '@plugin.manager.ckeditor5.plugin' - - '@plugin.manager.ckeditor4to5upgrade.plugin' - '@logger.channel.ckeditor5' - '@module_handler' - '@current_user' Drupal\ckeditor5\SmartDefaultSettings: '@ckeditor5.smart_default_settings' - ckeditor5.stylesheets.message: - class: Drupal\ckeditor5\CKEditor5StylesheetsMessage - arguments: - - '@theme_handler' - - '@config.factory' - Drupal\ckeditor5\CKEditor5StylesheetsMessage: '@ckeditor5.stylesheets.message' ckeditor5.ckeditor5_cache_tag: class: Drupal\ckeditor5\EventSubscriber\CKEditor5CacheTag arguments: ['@cache_tags.invalidator'] diff --git a/core/modules/ckeditor5/src/Annotation/CKEditor4To5Upgrade.php b/core/modules/ckeditor5/src/Annotation/CKEditor4To5Upgrade.php deleted file mode 100644 index d33472b74a1b309339283298de43658a744dec67..0000000000000000000000000000000000000000 --- a/core/modules/ckeditor5/src/Annotation/CKEditor4To5Upgrade.php +++ /dev/null @@ -1,50 +0,0 @@ -<?php - -declare(strict_types = 1); - -namespace Drupal\ckeditor5\Annotation; - -use Drupal\Component\Annotation\Plugin; - -/** - * Defines a CKEditor4To5Upgrade annotation object. - * - * Plugin Namespace: Plugin\CKEditor4To5Upgrade. - * - * @see \Drupal\ckeditor5\Plugin\CKEditor5PluginInterface - * @see \Drupal\ckeditor5\Plugin\CKEditor5PluginManagerInterface - * @see plugin_api - * - * @Annotation - */ -class CKEditor4To5Upgrade extends Plugin { - - /** - * The plugin ID. - * - * @var string - */ - public $id; - - /** - * The CKEditor 4 buttons for which an upgrade path is provided. - * - * @var string[] - */ - public $cke4_buttons; - - /** - * The CKEditor 4 plugins for whose settings an upgrade path is provided. - * - * @var string[] - */ - public $cke4_plugin_settings; - - /** - * The CKEditor 5 plugins with configurable subset with upgrade path provided. - * - * @var string[] - */ - public $cke5_plugin_elements_subset_configuration; - -} diff --git a/core/modules/ckeditor5/src/CKEditor5StylesheetsMessage.php b/core/modules/ckeditor5/src/CKEditor5StylesheetsMessage.php deleted file mode 100644 index 26aaaafd9e71becde310850cb6766a0d522e8d85..0000000000000000000000000000000000000000 --- a/core/modules/ckeditor5/src/CKEditor5StylesheetsMessage.php +++ /dev/null @@ -1,134 +0,0 @@ -<?php - -declare(strict_types = 1); - -namespace Drupal\ckeditor5; - -use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\Core\Extension\ThemeHandlerInterface; -use Drupal\Core\StringTranslation\StringTranslationTrait; - -/** - * Messaging for themes using the ckeditor_stylesheets setting. - * - * Messaging is provided when themes are found that use ckeditor_stylesheets - * without a corresponding ckeditor5-stylesheets setting. - * - * @internal - * This class may change at any time. It is not for use outside this module. - * @todo Remove in Drupal 11: https://www.drupal.org/project/ckeditor5/issues/3239012 - */ -final class CKEditor5StylesheetsMessage { - - use StringTranslationTrait; - - /** - * The theme handler. - * - * @var \Drupal\Core\Extension\ThemeHandlerInterface - */ - protected $themeHandler; - - /** - * The config factory. - * - * @var \Drupal\Core\Config\ConfigFactoryInterface - */ - protected $configFactory; - - /** - * Constructs a new CKEditor5StylesheetsMessage. - * - * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler - * The theme handler. - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The config factory to get the installed themes. - */ - public function __construct(ThemeHandlerInterface $theme_handler, ConfigFactoryInterface $config_factory) { - $this->themeHandler = $theme_handler; - $this->configFactory = $config_factory; - } - - /** - * Generates a warning related to ckeditor_stylesheets. - * - * Identifies themes using ckeditor_stylesheets without an equivalent - * ckeditor5-stylesheets setting. If such themes are found, a warning message - * is returned. - * - * @return \Drupal\Core\StringTranslation\PluralTranslatableMarkup|null - * A warning message where appropriate, otherwise null. - */ - public function getWarning() { - $themes = []; - $default_theme = $this->configFactory->get('system.theme')->get('default'); - if (!empty($default_theme)) { - $themes[$default_theme] = $this->themeHandler->listInfo()[$default_theme]->info; - } - - $admin_theme = $this->configFactory->get('system.theme')->get('admin'); - if (!empty($admin_theme) && $admin_theme !== $default_theme) { - $themes[$admin_theme] = $this->themeHandler->listInfo()[$admin_theme]->info; - } - - // Collect information on which themes/base themes have ckeditor_stylesheets - // configuration, but do not have corresponding ckeditor5-stylesheets - // configuration. - $ckeditor_stylesheets_use = []; - foreach ($themes as $theme_info) { - $this->checkForStylesheetsEquivalent($theme_info, $ckeditor_stylesheets_use); - } - - if (!empty($ckeditor_stylesheets_use)) { - // A subtheme may unnecessarily appear multiple times. - $ckeditor_stylesheets_use = array_unique($ckeditor_stylesheets_use); - $last_item = array_pop($ckeditor_stylesheets_use); - $stylesheets_warning = $this->formatPlural(count($ckeditor_stylesheets_use) + 1, - 'The %last_item theme has ckeditor_stylesheets configured without a corresponding ckeditor5-stylesheets configuration. See the <a href=":change_record">change record</a> for details.', - 'The %first_items and %last_item themes have ckeditor_stylesheets configured, but without corresponding ckeditor5-stylesheets configurations. See the <a href=":change_record">change record</a> for details.', - [ - '%last_item' => $last_item, - '%first_items' => implode(', ', $ckeditor_stylesheets_use), - ':change_record' => 'https://www.drupal.org/node/3259165', - ]); - - return $stylesheets_warning; - } - - return NULL; - } - - /** - * Checks themes using ckeditor_stylesheets for CKEditor 5 equivalents. - * - * @param array $theme_info - * The config of the theme to check. - * @param string[] $ckeditor_stylesheets_use - * Themes using ckeditor_stylesheets without a CKEditor 5 equivalent. - */ - private function checkForStylesheetsEquivalent(array $theme_info, array &$ckeditor_stylesheets_use) { - $theme_has_ckeditor5_stylesheets = isset($theme_info['ckeditor5-stylesheets']); - if (!empty($theme_info['ckeditor_stylesheets']) && !$theme_has_ckeditor5_stylesheets) { - $ckeditor_stylesheets_use[] = $theme_info['name']; - } - - // If the primary theme has ckeditor5-stylesheets configured, do not check - // base themes. The primary theme can potentially provide the - // ckeditor5-stylesheets config for itself and its base themes, so we err - // on the side of not showing a warning if this is possibly the case. - if ($theme_has_ckeditor5_stylesheets) { - return; - } - $base_theme = $theme_info['base theme'] ?? FALSE; - while ($base_theme) { - $base_theme_info = $this->themeHandler->listInfo()[$base_theme]->info; - $base_theme_has_ckeditor5_stylesheets = isset($base_theme_info['ckeditor5-stylesheets']); - - if (!empty($base_theme_info['ckeditor_stylesheets']) && !$base_theme_has_ckeditor5_stylesheets) { - $ckeditor_stylesheets_use[] = $base_theme_info['name']; - } - $base_theme = $base_theme_info['base theme'] ?? FALSE; - } - } - -} diff --git a/core/modules/ckeditor5/src/Plugin/CKEditor4To5Upgrade/Contrib.php b/core/modules/ckeditor5/src/Plugin/CKEditor4To5Upgrade/Contrib.php deleted file mode 100644 index ef62d2ed3662d8baa352e35549950ebbe977dcdf..0000000000000000000000000000000000000000 --- a/core/modules/ckeditor5/src/Plugin/CKEditor4To5Upgrade/Contrib.php +++ /dev/null @@ -1,85 +0,0 @@ -<?php - -declare(strict_types=1); - -namespace Drupal\ckeditor5\Plugin\CKEditor4To5Upgrade; - -// cspell:ignore codesnippet - -use Drupal\ckeditor5\HTMLRestrictions; -use Drupal\ckeditor5\Plugin\CKEditor4To5UpgradePluginInterface; -use Drupal\Core\Plugin\PluginBase; -use Drupal\filter\FilterFormatInterface; - -/** - * Provides the CKEditor 4 to 5 upgrade path for contrib plugins now in core. - * - * @CKEditor4To5Upgrade( - * id = "contrib", - * cke4_buttons = { - * "Code", - * "CodeSnippet", - * }, - * cke4_plugin_settings = { - * "codesnippet", - * }, - * cke5_plugin_elements_subset_configuration = { - * } - * ) - * - * @internal - * Plugin classes are internal. - */ -class Contrib extends PluginBase implements CKEditor4To5UpgradePluginInterface { - - /** - * {@inheritdoc} - */ - public function mapCKEditor4ToolbarButtonToCKEditor5ToolbarItem(string $cke4_button, HTMLRestrictions $text_format_html_restrictions): ?array { - switch ($cke4_button) { - // @see https://www.drupal.org/project/codetag - case 'Code': - return ['code']; - - // @see https://www.drupal.org/project/codesnippet - case 'CodeSnippet': - return ['codeBlock']; - - default: - throw new \OutOfBoundsException(); - } - } - - /** - * {@inheritdoc} - */ - public function mapCKEditor4SettingsToCKEditor5Configuration(string $cke4_plugin_id, array $cke4_plugin_settings): ?array { - switch ($cke4_plugin_id) { - case 'codesnippet': - $languages = []; - $enabled_cke4_languages = array_filter($cke4_plugin_settings['highlight_languages']); - foreach ($enabled_cke4_languages as $language) { - $languages[] = [ - 'language' => $language, - 'label' => $language, - ]; - } - return [ - 'ckeditor5_codeBlock' => [ - 'languages' => $languages, - ], - ]; - - default: - throw new \OutOfBoundsException(); - } - } - - /** - * {@inheritdoc} - */ - public function computeCKEditor5PluginSubsetConfiguration(string $cke5_plugin_id, FilterFormatInterface $text_format): ?array { - throw new \OutOfBoundsException(); - } - -} diff --git a/core/modules/ckeditor5/src/Plugin/CKEditor4To5Upgrade/Core.php b/core/modules/ckeditor5/src/Plugin/CKEditor4To5Upgrade/Core.php deleted file mode 100644 index d543359bb64d0f7a19636f7dbbde8c1aea68f015..0000000000000000000000000000000000000000 --- a/core/modules/ckeditor5/src/Plugin/CKEditor4To5Upgrade/Core.php +++ /dev/null @@ -1,308 +0,0 @@ -<?php - -declare(strict_types=1); - -namespace Drupal\ckeditor5\Plugin\CKEditor4To5Upgrade; - -use Drupal\ckeditor5\HTMLRestrictions; -use Drupal\ckeditor5\Plugin\CKEditor4To5UpgradePluginInterface; -use Drupal\ckeditor5\Plugin\CKEditor5Plugin\Style; -use Drupal\Core\Plugin\PluginBase; -use Drupal\filter\FilterFormatInterface; - -/** - * Provides the CKEditor 4 to 5 upgrade for Drupal core's CKEditor plugins. - * - * @CKEditor4To5Upgrade( - * id = "core", - * cke4_buttons = { - * "DrupalImage", - * "DrupalLink", - * "DrupalUnlink", - * "Bold", - * "Italic", - * "Underline", - * "Superscript", - * "Subscript", - * "BulletedList", - * "NumberedList", - * "Outdent", - * "Indent", - * "Undo", - * "Redo", - * "Blockquote", - * "JustifyLeft", - * "JustifyCenter", - * "JustifyRight", - * "JustifyBlock", - * "HorizontalRule", - * "Format", - * "Table", - * "Source", - * "Strike", - * "Cut", - * "Copy", - * "Paste", - * "PasteText", - * "PasteFromWord", - * "ShowBlocks", - * "Maximize", - * "-", - * "RemoveFormat", - * "Styles", - * "SpecialChar", - * "Language", - * "DrupalMediaLibrary", - * }, - * cke4_plugin_settings = { - * "stylescombo", - * "language", - * }, - * cke5_plugin_elements_subset_configuration = { - * "ckeditor5_heading", - * "ckeditor5_alignment", - * "ckeditor5_list", - * "ckeditor5_style", - * "media_media", - * } - * ) - * - * @internal - * Plugin classes are internal. - */ -class Core extends PluginBase implements CKEditor4To5UpgradePluginInterface { - - /** - * {@inheritdoc} - */ - public function mapCKEditor4ToolbarButtonToCKEditor5ToolbarItem(string $cke4_button, HTMLRestrictions $text_format_html_restrictions): ?array { - static $alignment_mapped; - switch ($cke4_button) { - // @see \Drupal\ckeditor\Plugin\CKEditorPlugin\DrupalImage - case 'DrupalImage': - return ['drupalInsertImage']; - - // @see \Drupal\ckeditor\Plugin\CKEditorPlugin\DrupalLink - case 'DrupalLink': - return ['link']; - - case 'DrupalUnlink': - return NULL; - - // @see \Drupal\ckeditor\Plugin\CKEditorPlugin\Internal - case 'Bold': - case 'Italic': - case 'Underline': - case 'Superscript': - case 'Subscript': - case 'BulletedList': - case 'NumberedList': - case 'Outdent': - case 'Indent': - case 'Undo': - case 'Redo': - return [lcfirst($cke4_button)]; - - case 'Blockquote': - return ['blockQuote']; - - case 'JustifyLeft': - case 'JustifyCenter': - case 'JustifyRight': - case 'JustifyBlock': - if (!isset($alignment_mapped)) { - $alignment_mapped = TRUE; - return ['alignment']; - } - return NULL; - - case 'HorizontalRule': - return ['horizontalLine']; - - case 'Format': - if ($text_format_html_restrictions->isUnrestricted()) { - // When no restrictions exist, all tags possibly supported by "Format" - // in CKEditor 4 must be supported. - return ['heading', 'codeBlock']; - } - $allowed_elements = $text_format_html_restrictions->getAllowedElements(); - // Check if <h*> is supported. - // Merely checking the existence of the array key is sufficient; this - // plugin does not set or need any additional attributes. - // @see \Drupal\filter\Plugin\FilterInterface::getHTMLRestrictions() - $intersect = array_intersect(['h2', 'h3', 'h4', 'h5', 'h6'], array_keys($allowed_elements)); - - // Do not return the 'codeBlock' toolbar item, not even when `<pre>` is - // allowed in the text format. This ensures that SmartDefaultSettings: - // - first adds the `code` toolbar item (for inline `<code>`) - // - then adds `codeBlock` toolbar item (for code blocks: `<pre><code>`) - // @see https://www.drupal.org/project/drupal/issues/3263384#comment-14446315 - return count($intersect) > 0 ? ['heading'] : NULL; - - case 'Table': - return ['insertTable']; - - case 'Source': - return ['sourceEditing']; - - case 'Strike': - return ['strikethrough']; - - case 'Cut': - case 'Copy': - case 'Paste': - case 'PasteText': - case 'PasteFromWord': - case 'Maximize': - case '-': - // @see https://www.drupal.org/project/ckeditor5/issues/3211049#comment-14167764 - return NULL; - - case 'ShowBlocks': - return ['showBlocks']; - - // @see \Drupal\ckeditor5\Plugin\CKEditor5Plugin\RemoveFormat - case 'RemoveFormat': - return ['removeFormat']; - - // @see \Drupal\ckeditor\Plugin\CKEditorPlugin\StylesCombo - case 'Styles': - return ['style']; - - // @see \Drupal\ckeditor5\Plugin\CKEditor5Plugin\specialCharacters - case 'SpecialChar': - return ['specialCharacters']; - - // @see \Drupal\ckeditor\Plugin\CKEditorPlugin\Language - case 'Language': - return ['textPartLanguage']; - - // @see \Drupal\media_library\Plugin\CKEditorPlugin\DrupalMediaLibrary - case 'DrupalMediaLibrary': - return ['drupalMedia']; - - default: - throw new \OutOfBoundsException(); - } - } - - /** - * {@inheritdoc} - */ - public function mapCKEditor4SettingsToCKEditor5Configuration(string $cke4_plugin_id, array $cke4_plugin_settings): ?array { - switch ($cke4_plugin_id) { - // @see \Drupal\ckeditor\Plugin\CKEditorPlugin\StylesCombo - case 'stylescombo': - if (!isset($cke4_plugin_settings['styles'])) { - $styles = []; - } - else { - [$styles] = Style::parseStylesFormValue($cke4_plugin_settings['styles']); - } - return [ - 'ckeditor5_style' => [ - 'styles' => $styles, - ], - ]; - - // @see \Drupal\ckeditor\Plugin\CKEditorPlugin\Language - case 'language': - // Identical configuration. - return ['ckeditor5_language' => $cke4_plugin_settings]; - - default: - throw new \OutOfBoundsException(); - } - } - - /** - * {@inheritdoc} - */ - public function computeCKEditor5PluginSubsetConfiguration(string $cke5_plugin_id, FilterFormatInterface $text_format): ?array { - switch ($cke5_plugin_id) { - case 'ckeditor5_heading': - $restrictions = $text_format->getHtmlRestrictions(); - if ($restrictions === FALSE) { - // The default is to allow all headings, which makes sense when there - // are no restrictions. - // @see \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Heading::DEFAULT_CONFIGURATION - return NULL; - } - // Otherwise, only enable headings that allowed by the restrictions. - $configuration = []; - foreach (range(1, 6) as $index) { - // Merely checking the existence of the array key is sufficient; this - // plugin does not set or need any additional attributes. - // @see \Drupal\filter\Plugin\FilterInterface::getHTMLRestrictions() - if (array_key_exists("h$index", $restrictions['allowed'])) { - $configuration['enabled_headings'][] = "heading$index"; - } - } - return $configuration; - - case 'ckeditor5_alignment': - $alignment_classes_to_types = [ - 'text-align-left' => 'left', - 'text-align-right' => 'right', - 'text-align-center' => 'center', - 'text-align-justify' => 'justify', - ]; - $restrictions = $text_format->getHtmlRestrictions(); - if ($restrictions === FALSE) { - // The default is to allow all alignments. This makes sense when there - // are no restrictions. - // @see \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Alignment::DEFAULT_CONFIGURATION - return NULL; - } - // Otherwise, enable alignment types based on the provided restrictions. - // I.e. if a tag is found with a text-align-{alignment type} class, - // activate that alignment type. - $configuration = []; - foreach ($restrictions['allowed'] as $tag) { - $classes = isset($tag['class']) && is_array($tag['class']) ? $tag['class'] : []; - foreach (array_keys($classes) as $class) { - if (isset($alignment_classes_to_types[$class])) { - $configuration['enabled_alignments'][] = $alignment_classes_to_types[$class]; - } - } - } - if (isset($configuration['enabled_alignments'])) { - $configuration['enabled_alignments'] = array_unique($configuration['enabled_alignments']); - } - return $configuration; - - case 'ckeditor5_list': - $restrictions = $text_format->getHtmlRestrictions(); - if ($restrictions === FALSE) { - // The default is to allow a reversed list and a start index, which makes sense when there - // are no restrictions. - // @see \Drupal\ckeditor5\Plugin\CKEditor5Plugin\ListPlugin::default_configuration() - return NULL; - } - $configuration = []; - $configuration['properties']['reversed'] = !empty($restrictions['allowed']['ol']['reversed']); - $configuration['properties']['startIndex'] = !empty($restrictions['allowed']['ol']['start']); - return $configuration; - - case 'media_media': - $restrictions = $text_format->getHtmlRestrictions(); - if ($restrictions === FALSE) { - // The default is to not allow the user to override the default view mode. - // @see \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Media::defaultConfiguration() - return NULL; - } - $configuration = []; - // Check if data-view-mode is allowed. - $configuration['allow_view_mode_override'] = !empty($restrictions['allowed']['drupal-media']['data-view-mode']); - return $configuration; - - case 'ckeditor5_style': - // @see mapCKEditor4SettingsToCKEditor5Configuration() - return NULL; - - default: - throw new \OutOfBoundsException(); - } - } - -} diff --git a/core/modules/ckeditor5/src/Plugin/CKEditor4To5UpgradePluginInterface.php b/core/modules/ckeditor5/src/Plugin/CKEditor4To5UpgradePluginInterface.php deleted file mode 100644 index 82e9b3c5da29582a8184acf95dbe043c6b4e706a..0000000000000000000000000000000000000000 --- a/core/modules/ckeditor5/src/Plugin/CKEditor4To5UpgradePluginInterface.php +++ /dev/null @@ -1,97 +0,0 @@ -<?php - -declare(strict_types = 1); - -namespace Drupal\ckeditor5\Plugin; - -use Drupal\ckeditor5\HTMLRestrictions; -use Drupal\Component\Plugin\PluginInspectionInterface; -use Drupal\filter\FilterFormatInterface; - -/** - * Defines an interface for CKEditor 4 to 5 upgrade plugins. - * - * @see \Drupal\ckeditor5\Plugin\CKEditor4To5UpgradePluginManager - * @see \Drupal\ckeditor5\Annotation\CKEditor4To5Upgrade - * @see plugin_api - */ -interface CKEditor4To5UpgradePluginInterface extends PluginInspectionInterface { - - /** - * Maps a CKEditor 4 button to the CKEditor 5 equivalent, if it exists. - * - * Generated by inspecting all \Drupal\ckeditor\CKEditorPluginButtonsInterface - * implementations. - * - * @param string $cke4_button - * A valid CKEditor 4 button name. - * @param \Drupal\ckeditor5\HTMLRestrictions $text_format_html_restrictions - * The restrictions of the text format, if this upgrade plugin needs to - * inspect the text format's HTML restrictions to make a decision. - * - * @return string[]|null - * The equivalent CKEditor 5 toolbar items, or NULL if no equivalent exists. - * In either case, the button names must be added to the annotation. - * - * @throws \OutOfBoundsException - * Thrown when this plugin does not know whether an equivalent exists. - * - * @see \Drupal\ckeditor\CKEditorPluginButtonsInterface - * @see \Drupal\ckeditor5\Annotation\CKEditor4To5Upgrade - */ - public function mapCKEditor4ToolbarButtonToCKEditor5ToolbarItem(string $cke4_button, HTMLRestrictions $text_format_html_restrictions): ?array; - - /** - * Maps CKEditor 4 settings to the CKEditor 5 equivalent, if needed. - * - * Not every CKEditor 5 plugin has settings; some CKEditor 5 plugins may have - * settings that the CKEditor 4 equivalent did not and vice versa. Therefore - * the complete CKEditor 4 settings are provided, and any CKEditor 5 setting - * can be set. - * - * @param string $cke4_plugin_id - * The CKEditor 4 plugin whose settings need to be mapped. - * @param array $cke4_plugin_settings - * The settings for this CKEditor 4 plugin. - * - * @return array|null - * NULL if not needed, otherwise an array with a single key-value pair: - * - key: the plugin ID of the equivalent CKEditor 5 plugin - * - value: the equivalent settings - * In either case, the button name must be added to the annotation. - * - * @throws \OutOfBoundsException - * Thrown when this plugin does not know whether an equivalent exists. - * - * @see \Drupal\ckeditor\CKEditorPluginConfigurableInterface - * @see \Drupal\ckeditor5\Annotation\CKEditor4To5Upgrade - */ - public function mapCKEditor4SettingsToCKEditor5Configuration(string $cke4_plugin_id, array $cke4_plugin_settings): ?array; - - /** - * Computes elements subset configuration for CKEditor 5 plugin. - * - * Every CKEditor 5 plugin that implements the elements subset interface must - * implement this as well, to ensure a smooth upgrade path. - * - * @param string $cke5_plugin_id - * The CKEditor 5 plugin whose subset configuration needs to be computed. - * @param \Drupal\filter\FilterFormatInterface $text_format - * The text format based on whose restrictions this should be computed. - * - * @return array|null - * NULL if not needed, otherwise a configuration array (which can itself be - * a subset of the default configuration of this CKEditor 5 plugin: perhaps - * only some of the configuration values determine the subset). - * - * @throws \OutOfBoundsException - * Thrown when no upgrade path exists. - * @throws \LogicException - * Thrown when a plugin claims to provide an upgrade path but does not. - * - * @see \Drupal\ckeditor5\Plugin\CKEditor5PluginElementsSubsetInterface - * @see \Drupal\ckeditor5\Annotation\CKEditor4To5Upgrade - */ - public function computeCKEditor5PluginSubsetConfiguration(string $cke5_plugin_id, FilterFormatInterface $text_format): ?array; - -} diff --git a/core/modules/ckeditor5/src/Plugin/CKEditor4To5UpgradePluginManager.php b/core/modules/ckeditor5/src/Plugin/CKEditor4To5UpgradePluginManager.php deleted file mode 100644 index d08b806a619125fed1157714dd46c2e96d445f4f..0000000000000000000000000000000000000000 --- a/core/modules/ckeditor5/src/Plugin/CKEditor4To5UpgradePluginManager.php +++ /dev/null @@ -1,230 +0,0 @@ -<?php - -declare(strict_types = 1); - -namespace Drupal\ckeditor5\Plugin; - -use Drupal\ckeditor5\Annotation\CKEditor4To5Upgrade; -use Drupal\ckeditor5\HTMLRestrictions; -use Drupal\Component\Assertion\Inspector; -use Drupal\Core\Cache\CacheBackendInterface; -use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\Plugin\DefaultPluginManager; -use Drupal\filter\FilterFormatInterface; - -/** - * Provides a CKEditor 4 to 5 upgrade plugin manager. - * - * @see \Drupal\ckeditor5\Plugin\CKEditor4To5UpgradePluginInterface - * @see \Drupal\ckeditor5\Annotation\CKEditor4To5Upgrade - * @see plugin_api - * - * @internal - */ -class CKEditor4To5UpgradePluginManager extends DefaultPluginManager { - - /** - * A map of CKEditor 4 buttons to an upgrade plugin ID. - * - * @var array - */ - protected $cke4ButtonsMap; - - /** - * A map of CKEditor 4 plugins with settings to an upgrade plugin ID. - * - * @var array - */ - protected $cke4PluginSettingsMap; - - /** - * A map of CKEditor 5 plugins with configurable subset to upgrade plugin ID. - * - * @var array - */ - protected $cke5SubsetConfigurationMap; - - /** - * Constructs a CKEditor4To5UpgradePluginManager object. - * - * @param \Traversable $namespaces - * An object that implements \Traversable which contains the root paths - * keyed by the corresponding namespace to look for plugin implementations. - * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend - * Cache backend instance to use. - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler - * The module handler to invoke the alter hook with. - */ - public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/CKEditor4To5Upgrade', $namespaces, $module_handler, CKEditor4To5UpgradePluginInterface::class, CKEditor4To5Upgrade::class); - - $this->alterInfo('ckeditor4to5upgrade_plugin_info'); - $this->setCacheBackend($cache_backend, 'ckeditor4to5upgrade_plugins'); - } - - /** - * Validates plugin definitions: avoids conflicts. Builds maps for later use. - */ - protected function validateAndBuildMaps(): void { - if ($this->cke4ButtonsMap !== NULL) { - return; - } - - foreach ($this->getDefinitions() as $upgrade_plugin_id => $definition) { - // Only one CKEditor4To5Upgrade plugin can define the upgrade path for a - // CKEditor 4 button. - if (isset($definition['cke4_buttons'])) { - assert(Inspector::assertAllStrings($definition['cke4_buttons'])); - foreach ($definition['cke4_buttons'] as $cke4_button_id) { - if (isset($this->cke4ButtonsMap[$cke4_button_id])) { - throw new \OutOfBoundsException(sprintf('The "%s" CKEditor 4 button is already being upgraded by the "%s" CKEditor4To5Upgrade plugin, the "%s" plugin is as well. This conflict needs to be resolved.', $cke4_button_id, $this->cke4ButtonsMap[$cke4_button_id], $upgrade_plugin_id)); - } - $this->cke4ButtonsMap[$cke4_button_id] = $upgrade_plugin_id; - } - } - - // Only one CKEditor4To5Upgrade plugin can define the upgrade path for a - // CKEditor 4 plugin's settings. - if (isset($definition['cke4_plugin_settings'])) { - assert(Inspector::assertAllStrings($definition['cke4_plugin_settings'])); - foreach ($definition['cke4_plugin_settings'] as $cke4_plugin_id) { - if (isset($this->cke4PluginSettingsMap[$cke4_plugin_id])) { - throw new \OutOfBoundsException(sprintf('The "%s" CKEditor 4 plugin\'s settings are already being upgraded by the "%s" CKEditor4To5Upgrade plugin, the "%s" plugin is as well. This conflict needs to be resolved.', $cke4_plugin_id, $this->cke4PluginSettingsMap[$cke4_plugin_id], $upgrade_plugin_id)); - } - $this->cke4PluginSettingsMap[$cke4_plugin_id] = $upgrade_plugin_id; - } - } - - // Only one CKEditor4To5Upgrade plugin can define the upgrade path for a - // CKEditor 5 plugin's elements subset configuration. - if (isset($definition['cke5_plugin_elements_subset_configuration'])) { - assert(Inspector::assertAllStrings($definition['cke5_plugin_elements_subset_configuration'])); - foreach ($definition['cke5_plugin_elements_subset_configuration'] as $cke5_plugin_id) { - if (isset($this->cke5SubsetConfigurationMap[$cke5_plugin_id])) { - throw new \OutOfBoundsException(sprintf('The "%s" CKEditor 5 plugin\'s elements subset configuration is already being computed by the "%s" CKEditor4To5Upgrade plugin, the "%s" plugin is as well. This conflict needs to be resolved.', $cke5_plugin_id, $this->cke5SubsetConfigurationMap[$cke5_plugin_id], $upgrade_plugin_id)); - } - $this->cke5SubsetConfigurationMap[$cke5_plugin_id] = $upgrade_plugin_id; - } - } - } - } - - /** - * Maps a CKEditor 4 button to the CKEditor 5 equivalent, if it exists. - * - * Generated by inspecting all \Drupal\ckeditor\CKEditorPluginButtonsInterface - * implementations. - * - * @param string $cke4_button - * A valid CKEditor 4 button name. - * @param \Drupal\ckeditor5\HTMLRestrictions $text_format_html_restrictions - * The restrictions of the text format, to allow an upgrade plugin to - * inspect the text format's HTML restrictions to make a decision. - * - * @return string[]|null - * The equivalent CKEditor 5 toolbar items, or NULL if no equivalent exists. - * - * @throws \OutOfBoundsException - * Thrown when no upgrade path exists. - * @throws \LogicException - * Thrown when a plugin claims to provide an upgrade path but does not. - * - * @see \Drupal\ckeditor\CKEditorPluginButtonsInterface - */ - public function mapCKEditor4ToolbarButtonToCKEditor5ToolbarItem(string $cke4_button, HTMLRestrictions $text_format_html_restrictions): ?array { - $this->validateAndBuildMaps(); - - if (!isset($this->cke4ButtonsMap[$cke4_button])) { - throw new \OutOfBoundsException(sprintf('No upgrade path found for the "%s" button.', $cke4_button)); - } - - $plugin_id = $this->cke4ButtonsMap[$cke4_button]; - try { - return $this->createInstance($plugin_id)->mapCKEditor4ToolbarButtonToCKEditor5ToolbarItem($cke4_button, $text_format_html_restrictions); - } - catch (\OutOfBoundsException $e) { - throw new \LogicException(sprintf('The "%s" CKEditor4To5Upgrade plugin claims to provide an upgrade path for the "%s" CKEditor 4 button but does not.', $plugin_id, $cke4_button)); - } - } - - /** - * Maps CKEditor 4 settings to the CKEditor 5 equivalent, if needed. - * - * Not every CKEditor 5 plugin has settings; some CKEditor 5 plugins may have - * settings that the CKEditor 4 equivalent did not and vice versa. Therefore - * the complete CKEditor 4 settings are provided, and any CKEditor 5 setting - * can be set. - * - * @param string $cke4_plugin_id - * The CKEditor 4 plugin whose settings need to be mapped. - * @param array $cke4_plugin_settings - * The settings for this CKEditor 4 plugin. - * - * @return array|null - * NULL if not needed, otherwise an array with a single key-value pair: - * - key: the plugin ID of the equivalent CKEditor 5 plugin - * - value: the equivalent settings - * - * @throws \OutOfBoundsException - * Thrown when no upgrade path exists. - * @throws \LogicException - * Thrown when a plugin claims to provide an upgrade path but does not. - * - * @see \Drupal\ckeditor\CKEditorPluginConfigurableInterface - */ - public function mapCKEditor4SettingsToCKEditor5Configuration(string $cke4_plugin_id, array $cke4_plugin_settings): ?array { - $this->validateAndBuildMaps(); - - if (!isset($this->cke4PluginSettingsMap[$cke4_plugin_id])) { - throw new \OutOfBoundsException(sprintf('No upgrade path found for the "%s" plugin settings.', $cke4_plugin_id)); - } - - $plugin_id = $this->cke4PluginSettingsMap[$cke4_plugin_id]; - try { - return $this->createInstance($plugin_id)->mapCKEditor4SettingsToCKEditor5Configuration($cke4_plugin_id, $cke4_plugin_settings); - } - catch (\OutOfBoundsException $e) { - throw new \LogicException(sprintf('The "%s" CKEditor4To5Upgrade plugin claims to provide an upgrade path for the "%s" CKEditor 4 plugin settings but does not.', $plugin_id, $cke4_plugin_id)); - } - } - - /** - * Computes elements subset configuration for CKEditor 5 plugin. - * - * Every CKEditor 5 plugin that implements the elements subset interface must - * implement this as well, to ensure a smooth upgrade path. - * - * @param string $cke5_plugin_id - * The CKEditor 5 plugin whose subset configuration needs to be computed. - * @param \Drupal\filter\FilterFormatInterface $text_format - * The text format based on whose restrictions this should be computed. - * - * @return array|null - * NULL if not needed, otherwise a configuration array (which can itself be - * a subset of the default configuration of this CKEditor 5 plugin: perhaps - * only some of the configuration values determine the subset). - * - * @throws \OutOfBoundsException - * Thrown when no upgrade path exists. - * @throws \LogicException - * Thrown when a plugin claims to provide an upgrade path but does not. - * - * @see \Drupal\ckeditor5\Plugin\CKEditor5PluginElementsSubsetInterface - */ - public function computeCKEditor5PluginSubsetConfiguration(string $cke5_plugin_id, FilterFormatInterface $text_format): ?array { - $this->validateAndBuildMaps(); - - if (!isset($this->cke5SubsetConfigurationMap[$cke5_plugin_id])) { - throw new \OutOfBoundsException(sprintf('No upgrade path found for the "%s" elements subset configuration.', $cke5_plugin_id)); - } - - $plugin_id = $this->cke5SubsetConfigurationMap[$cke5_plugin_id]; - try { - return $this->createInstance($plugin_id)->computeCKEditor5PluginSubsetConfiguration($cke5_plugin_id, $text_format); - } - catch (\OutOfBoundsException $e) { - throw new \LogicException(sprintf('The "%s" CKEditor4To5Upgrade plugin claims to provide an upgrade path for the "%s" CKEditor 4 plugin settings but does not.', $plugin_id, $cke5_plugin_id)); - } - } - -} diff --git a/core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/Style.php b/core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/Style.php index e0833c965d113651ba53b3d2f295f63d89e17b49..d925f89c305f09d876ebd79e7c5c1f3474449e14 100644 --- a/core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/Style.php +++ b/core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/Style.php @@ -98,12 +98,8 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form * - element: the CKEditor 5 element equivalent of the tag + classes * * @internal - * This method is public only to allow the CKEditor 4 to 5 upgrade path to - * reuse this logic. Mark this private in https://www.drupal.org/i/3239012. - * - * @see \Drupal\ckeditor5\Plugin\CKEditor4To5Upgrade\Core::mapCKEditor4SettingsToCKEditor5Configuration() */ - public static function parseStylesFormValue(string $form_value): array { + private static function parseStylesFormValue(string $form_value): array { $invalid_lines = []; $lines = explode("\n", $form_value); diff --git a/core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php b/core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php index 821f4cc3b1b9e9096528eaf1fc0a28bdaf54bfb2..60cdff3ac65f8aa076542941473471760b1d99ef 100644 --- a/core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php +++ b/core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php @@ -4,7 +4,6 @@ namespace Drupal\ckeditor5\Plugin\Editor; -use Drupal\ckeditor5\CKEditor5StylesheetsMessage; use Drupal\ckeditor5\HTMLRestrictions; use Drupal\ckeditor5\Plugin\CKEditor5Plugin\Heading; use Drupal\ckeditor5\Plugin\CKEditor5PluginDefinition; @@ -99,13 +98,6 @@ class CKEditor5 extends EditorBase implements ContainerFactoryPluginInterface { */ protected $cache; - /** - * The ckeditor_stylesheets message utility. - * - * @var \Drupal\ckeditor5\CKEditor5StylesheetsMessage - */ - private $stylesheetsMessage; - /** * A logger instance. * @@ -132,19 +124,16 @@ class CKEditor5 extends EditorBase implements ContainerFactoryPluginInterface { * The smart default settings utility. * @param \Drupal\Core\Cache\CacheBackendInterface $cache * The cache. - * @param \Drupal\ckeditor5\CKEditor5StylesheetsMessage $stylesheets_message - * The ckeditor_stylesheets message utility. * @param \Psr\Log\LoggerInterface $logger * A logger instance. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, CKEditor5PluginManagerInterface $ckeditor5_plugin_manager, LanguageManagerInterface $language_manager, ModuleHandlerInterface $module_handler, SmartDefaultSettings $smart_default_settings, CacheBackendInterface $cache, CKEditor5StylesheetsMessage $stylesheets_message, LoggerInterface $logger) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, CKEditor5PluginManagerInterface $ckeditor5_plugin_manager, LanguageManagerInterface $language_manager, ModuleHandlerInterface $module_handler, SmartDefaultSettings $smart_default_settings, CacheBackendInterface $cache, LoggerInterface $logger) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->ckeditor5PluginManager = $ckeditor5_plugin_manager; $this->languageManager = $language_manager; $this->moduleHandler = $module_handler; $this->smartDefaultSettings = $smart_default_settings; $this->cache = $cache; - $this->stylesheetsMessage = $stylesheets_message; $this->logger = $logger; } @@ -161,7 +150,6 @@ public static function create(ContainerInterface $container, array $configuratio $container->get('module_handler'), $container->get('ckeditor5.smart_default_settings'), $container->get('cache.default'), - $container->get('ckeditor5.stylesheets.message'), $container->get('logger.channel.ckeditor5') ); } @@ -298,23 +286,6 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta $form_state->set('editor', $editor); } - if ($css_warning = $this->stylesheetsMessage->getWarning()) { - // Explicitly render this single warning message visually close to the - // text editor since this is a very long form. Otherwise, it may be - // interpreted as a text format problem, or ignored entirely. - // All other messages will be rendered in the default location. - // @see \Drupal\Core\Render\Element\StatusMessages - $form['css_warning'] = [ - '#theme' => 'status_messages', - '#message_list' => [ - 'warning' => [$css_warning], - ], - '#status_headings' => [ - 'warning' => $this->t('Warning message'), - ], - ]; - } - // AJAX validation errors should appear visually close to the text editor // since this is a very long form: otherwise they would not be noticed. $form['real_time_validation_errors_location'] = [ diff --git a/core/modules/ckeditor5/src/SmartDefaultSettings.php b/core/modules/ckeditor5/src/SmartDefaultSettings.php index 5d3e0b243947bc02145191fb54b740fa445c2f92..f270dc9a316fc9bfdb5276d6a5a65eb8d2abb896 100644 --- a/core/modules/ckeditor5/src/SmartDefaultSettings.php +++ b/core/modules/ckeditor5/src/SmartDefaultSettings.php @@ -4,12 +4,9 @@ namespace Drupal\ckeditor5; -use Drupal\ckeditor5\Plugin\CKEditor5PluginConfigurableInterface; use Drupal\ckeditor5\Plugin\CKEditor5PluginDefinition; -use Drupal\ckeditor5\Plugin\CKEditor5PluginElementsSubsetInterface; use Drupal\ckeditor5\Plugin\CKEditor5PluginManagerInterface; use Drupal\Component\Assertion\Inspector; -use Drupal\Component\Plugin\PluginManagerInterface; use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Messenger\MessengerInterface; @@ -38,13 +35,6 @@ final class SmartDefaultSettings { */ protected $pluginManager; - /** - * The CKEditor 4 to 5 upgrade plugin manager. - * - * @var \Drupal\Component\Plugin\PluginManagerInterface - */ - protected $upgradePluginManager; - /** * The module handler. * @@ -71,8 +61,6 @@ final class SmartDefaultSettings { * * @param \Drupal\ckeditor5\Plugin\CKEditor5PluginManagerInterface $plugin_manager * The CKEditor 5 plugin manager. - * @param \Drupal\Component\Plugin\PluginManagerInterface $upgrade_plugin_manager - * The CKEditor 4 to 5 upgrade plugin manager. * @param \Psr\Log\LoggerInterface $logger * A logger instance. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler @@ -80,9 +68,8 @@ final class SmartDefaultSettings { * @param \Drupal\Core\Session\AccountInterface $current_user * The current user. */ - public function __construct(CKEditor5PluginManagerInterface $plugin_manager, PluginManagerInterface $upgrade_plugin_manager, LoggerInterface $logger, ModuleHandlerInterface $module_handler, AccountInterface $current_user) { + public function __construct(CKEditor5PluginManagerInterface $plugin_manager, LoggerInterface $logger, ModuleHandlerInterface $module_handler, AccountInterface $current_user) { $this->pluginManager = $plugin_manager; - $this->upgradePluginManager = $upgrade_plugin_manager; $this->logger = $logger; $this->moduleHandler = $module_handler; $this->currentUser = $current_user; @@ -92,8 +79,8 @@ public function __construct(CKEditor5PluginManagerInterface $plugin_manager, Plu * Computes the closest possible equivalent settings for switching to CKEditor 5. * * @param \Drupal\editor\EditorInterface|null $text_editor - * The editor being reconfigured for CKEditor 5 to match the CKEditor 4 - * settings as closely as possible (if it was using CKEditor 4). + * The editor being reconfigured for CKEditor 5; infer the settings based on + * the HTML restrictions. * @param \Drupal\filter\FilterFormatInterface $text_format * The text format for which to compute smart default settings. * @@ -144,27 +131,18 @@ public function computeSmartDefaultSettings(?EditorInterface $text_editor, Filte $editor->setEditor('ckeditor5'); $source_editing_additions = HTMLRestrictions::emptySet(); - // Compute the appropriate settings based on the CKEditor 4 configuration - // if it exists. + // Compute the appropriate settings based on the HTML restrictions of the + // text format. $old_editor = $editor->id() ? Editor::load($editor->id()) : NULL; $old_editor_restrictions = $old_editor ? HTMLRestrictions::fromTextFormat($old_editor->getFilterFormat()) : HTMLRestrictions::emptySet(); // @todo Remove in https://www.drupal.org/project/drupal/issues/3245351 if ($old_editor) { + // When switching from another text editor, use CKEditor 5's default + // settings. + // @see \Drupal\ckeditor5\Plugin\Editor\CKEditor5::getDefaultSettings() + $editor->setSettings(Editor::create(['editor' => 'ckeditor5'])->getSettings()); $editor->setImageUploadSettings($old_editor->getImageUploadSettings()); } - if ($old_editor && $old_editor->getEditor() === 'ckeditor') { - [$upgraded_settings, $messages] = $this->createSettingsFromCKEditor4($old_editor->getSettings(), HTMLRestrictions::fromTextFormat($old_editor->getFilterFormat())); - $editor->setSettings($upgraded_settings); - // *Before* determining which elements are still needed for this text - // format, ensure that all already enabled plugins that are configurable - // have valid settings. - // For all already enabled plugins, find the ones that are configurable, - // and add their default settings. For enabled plugins with element - // subsets, compute the appropriate settings to achieve the subset that - // matches the original text format restrictions. - $this->addDefaultSettingsForEnabledConfigurablePlugins($editor); - $this->computeSubsetSettingForEnabledPluginsWithSubsets($editor, $text_format); - } // Add toolbar items based on HTML tags and attributes. // NOTE: Helper updates $editor->settings by reference and returns info for the message. @@ -236,28 +214,7 @@ public function computeSmartDefaultSettings(?EditorInterface $text_editor, Filte // and add their default settings. For enabled plugins with element subsets, // compute the appropriate settings to achieve the subset that matches the // original text format restrictions. - // Note: if switching from CKEditor 4, this will already have happened for - // plugins that were already enabled in CKEditor 4. It's harmless to compute - // this again. $this->addDefaultSettingsForEnabledConfigurablePlugins($editor); - $this->computeSubsetSettingForEnabledPluginsWithSubsets($editor, $text_format); - - // In CKEditor 4, it's possible for settings to exist for plugins that are - // not actually enabled. During the upgrade path, these would then be mapped - // to equivalent CKEditor 5 configuration. But CKEditor 5 does not allow - // configuration to be stored for disabled plugins. Therefore determine - // which plugins actually are enabled, and omit the (upgraded) plugin - // configuration for disabled plugins. - // @see \Drupal\ckeditor5\Plugin\CKEditor4To5UpgradePluginInterface::mapCKEditor4SettingsToCKEditor5Configuration() - if ($old_editor && $old_editor->getEditor() === 'ckeditor') { - $enabled_definitions = $this->pluginManager->getEnabledDefinitions($editor); - $enabled_configurable_definitions = array_filter($enabled_definitions, function (CKEditor5PluginDefinition $definition): bool { - return is_a($definition->getClass(), CKEditor5PluginConfigurableInterface::class, TRUE); - }); - $settings = $editor->getSettings(); - $settings['plugins'] = array_intersect_key($settings['plugins'], $enabled_configurable_definitions); - $editor->setSettings($settings); - } if ($has_html_restrictions) { // Determine what tags/attributes are allowed in this text format that were @@ -401,6 +358,8 @@ private function addTagsToSourceEditing(EditorInterface $editor, HTMLRestriction $settings = $editor->getSettings(); if (!isset($settings['toolbar']['items']) || !in_array('sourceEditing', $settings['toolbar']['items'])) { $messages[MessengerInterface::TYPE_STATUS][] = $this->t('The <em>Source Editing</em> plugin was enabled to support tags and/or attributes that are not explicitly supported by any available CKEditor 5 plugins.'); + // Add the "Source Editing" toolbar item in a new group. + $settings['toolbar']['items'][] = '|'; $settings['toolbar']['items'][] = 'sourceEditing'; } $allowed_tags_array = $settings['plugins']['ckeditor5_sourceEditing']['allowed_tags'] ?? []; @@ -410,98 +369,6 @@ private function addTagsToSourceEditing(EditorInterface $editor, HTMLRestriction return $messages; } - /** - * Creates equivalent CKEditor 5 settings from CKEditor 4 settings. - * - * @param array $ckeditor4_settings - * The value for "settings" in a Text Editor config entity configured to use - * CKEditor 4. - * @param \Drupal\ckeditor5\HTMLRestrictions $text_format_html_restrictions - * The restrictions of the text format, to allow an upgrade plugin to - * inspect the text format's HTML restrictions to make a decision. - * - * @return array - * An array with two values: - * 1. An equivalent value for CKEditor 5. - * 2. Messages explaining upgrade path issues. - * - * @throws \LogicException - * Thrown when an upgrade plugin is attempting to generate plugin settings - * for a CKEditor 4 plugin upgrade path that have already been generated. - */ - private function createSettingsFromCKEditor4(array $ckeditor4_settings, HTMLRestrictions $text_format_html_restrictions): array { - $settings = [ - 'toolbar' => [ - 'items' => [], - ], - 'plugins' => [], - ]; - $messages = []; - - // First: toolbar items. - // @see \Drupal\ckeditor\CKEditorPluginButtonsInterface - foreach ($ckeditor4_settings['toolbar']['rows'] as $row) { - foreach ($row as $group) { - $some_added = FALSE; - foreach ($group['items'] as $cke4_button) { - try { - $equivalent = $this->upgradePluginManager->mapCKEditor4ToolbarButtonToCKEditor5ToolbarItem($cke4_button, $text_format_html_restrictions); - } - catch (\OutOfBoundsException $e) { - $this->logger->warning('The CKEditor 4 button %button does not have a known upgrade path. If it allowed editing markup, then you can do so now through the Source Editing functionality.', [ - '%button' => $cke4_button, - ]); - $messages[MessengerInterface::TYPE_WARNING][] = $this->t('The CKEditor 4 button %button does not have a known upgrade path. If it allowed editing markup, then you can do so now through the Source Editing functionality.', [ - '%button' => $cke4_button, - ]); - continue; - } - if ($equivalent) { - $settings['toolbar']['items'] = array_merge($settings['toolbar']['items'], $equivalent); - $some_added = TRUE; - } - } - // Add a CKEditor 5 toolbar group separator for every group. - if ($some_added) { - $settings['toolbar']['items'][] = '|'; - } - } - } - // Remove the trailing CKEditor 5 toolbar group separator. - array_pop($settings['toolbar']['items']); - // Strip the CKEditor 4 buttons without a CKEditor 5 equivalent. - $settings['toolbar']['items'] = array_filter($settings['toolbar']['items']); - - // Second: plugin settings. - // @see \Drupal\ckeditor\CKEditorPluginConfigurableInterface - $enabled_ckeditor4_plugins_with_settings = $ckeditor4_settings['plugins']; - foreach ($enabled_ckeditor4_plugins_with_settings as $cke4_plugin_id => $cke4_plugin_settings) { - try { - $cke5_plugin_settings = $this->upgradePluginManager->mapCKEditor4SettingsToCKEditor5Configuration($cke4_plugin_id, $cke4_plugin_settings); - if ($cke5_plugin_settings === NULL) { - continue; - } - assert(count($cke5_plugin_settings) === 1); - $cke5_plugin_id = array_keys($cke5_plugin_settings)[0]; - if (isset($settings['plugins'][$cke5_plugin_id])) { - throw new \LogicException(sprintf('The %s plugin settings have already been upgraded. Only a single @CKEditor4To5Upgrade is allowed to migrate the settings for a particular CKEditor 4 plugin.', $cke5_plugin_id)); - } - $settings['plugins'] += $cke5_plugin_settings; - } - catch (\OutOfBoundsException $e) { - $this->logger->warning('The %cke4_plugin_id plugin settings do not have a known upgrade path.', [ - '%cke4_plugin_id' => $cke4_plugin_id, - ]); - $messages[MessengerInterface::TYPE_WARNING][] = $this->t('The %cke4_plugin_id plugin settings do not have a known upgrade path.', [ - '%cke4_plugin_id' => $cke4_plugin_id, - ]); - continue; - } - } - - return [$settings, $messages]; - } - /** * Computes net new needed elements when considering adding the given plugin. * @@ -614,6 +481,8 @@ private static function computeSurplusScore(HTMLRestrictions $surplus, HTMLRestr * @param \Drupal\ckeditor5\Plugin\CKEditor5PluginDefinition[] $disabled_plugin_definitions * The list of not yet enabled CKEditor 5 plugin definitions, amongst which * candidates must be found. + * @param \Drupal\editor\EditorInterface $prospective_editor + * The in-progress prospective editor to be generated by this class. * * @return array * A nested array with a tree structure covering: @@ -629,15 +498,52 @@ private static function computeSurplusScore(HTMLRestrictions $surplus, HTMLRestr * always a leaf, and a selected CKEditor 5 plugin ID is always the parent * of a leaf. */ - private static function getCandidates(HTMLRestrictions $provided, HTMLRestrictions $still_needed, array $disabled_plugin_definitions): array { + private function getCandidates(HTMLRestrictions $provided, HTMLRestrictions $still_needed, array $disabled_plugin_definitions, EditorInterface $prospective_editor): array { $plugin_candidates = []; if (!$still_needed->allowsNothing()) { foreach ($disabled_plugin_definitions as $definition) { // Only proceed if the plugin has configured elements and the plugin - // does not have conditions. In the future we could add support for - // automatically enabling filters, but for now we assume that the filter - // configuration cannot be modified. - if (!$definition->hasConditions() && $definition->hasElements()) { + // does not have conditions, or only conditions that are met. In the + // future we could add support for automatically enabling filters, but + // for now we assume that the filter configuration cannot be modified. + if (!$definition->hasElements()) { + continue; + } + if (!$definition->hasConditions()) { + // Any plugin that has no conditions is a viable candidate. + $is_viable_candidate = TRUE; + } + else { + $is_viable_candidate = TRUE; + foreach ($definition->getConditions() as $condition_type => $required_value) { + // @see \Drupal\ckeditor5\Plugin\CKEditor5PluginManager::isPluginDisabled() + // @see \Drupal\ckeditor5\Plugin\CKEditor5PluginDefinition::validateDrupalAspects() + $is_viable_candidate = match ($condition_type) { + // If this requires a toolbar item that is provided by this + // plugin, then this is a viable candidate: placing this plugin's + // toolbar item suffices. + 'toolbarItem' => array_key_exists($definition->getConditions()['toolbarItem'], $definition->getToolbarItems()), + // The image upload status is not modified, so if the current + // value matches the condition, then this is a viable candidate. + 'imageUploadStatus' => ($prospective_editor->getImageUploadSettings()['status'] ?? FALSE) === $required_value, + // The set of filters is not modified, so if the required filter + // is already enabled, then this is a viable candidate. + // @todo Simplify in https://www.drupal.org/project/drupal/issues/2385047 + 'filter' => $prospective_editor->getFilterFormat()->filters()->has($required_value) && $prospective_editor->getFilterFormat()->filters()->get($required_value)->status, + // The default configuration is used for each plugin that would be + // enabled, so if the default configuration contains the required + // configuration, then this is a viable candidate. + 'requiresConfiguration' => array_intersect($this->pluginManager->createInstance($definition->id())->defaultConfiguration(), $required_value) === $required_value, + // If this requires plugins already in the current prospective + // editor, then this is a viable candidate. + 'plugins' => array_intersect($required_value, array_keys($this->pluginManager->getEnabledDefinitions($prospective_editor))) === $required_value, + }; + if (!$is_viable_candidate) { + break; + } + } + } + if ($is_viable_candidate) { [$net_new, $surplus_additions] = self::computeNetNewElementsForPlugin($provided, $still_needed, $definition); if (!$net_new->allowsNothing()) { $plugin_id = $definition->id(); @@ -806,7 +712,20 @@ private static function selectCandidate(array $candidates, HTMLRestrictions $sti private function addToolbarItemsToMatchHtmlElementsInFormat(FilterFormatInterface $format, EditorInterface $editor): ?array { $html_restrictions_needed_elements = $format->getHtmlRestrictions(); if ($html_restrictions_needed_elements === FALSE) { - return NULL; + // There are no HTML restrictions, so configure CKEditor 5 to allow + // arbitrary markup to be entered. + $editor_settings_to_update = $editor->getSettings(); + // Create new group for all the added toolbar items. + $editor_settings_to_update['toolbar']['items'][] = '|'; + $editor_settings_to_update['toolbar']['items'][] = 'sourceEditing'; + $editor_settings_to_update['plugins']['ckeditor5_sourceEditing']['allowed_tags'] = []; + $editor->setSettings($editor_settings_to_update); + return [ + NULL, + NULL, + HTMLRestrictions::emptySet(), + $this->pluginManager->getDefinition('ckeditor5_sourceEditing'), + ]; } $all_definitions = $this->pluginManager->getDefinitions(); @@ -835,11 +754,24 @@ private function addToolbarItemsToMatchHtmlElementsInFormat(FilterFormatInterfac if (!$still_needed->allowsNothing()) { // Select plugins for supporting the still needed plain tags. - $plugin_candidates_plain_tags = self::getCandidates($provided_plain_tags, $still_needed_plain_tags, $disabled_definitions); + $prospective_editor = clone $editor; + $plugin_candidates_plain_tags = self::getCandidates($provided_plain_tags, $still_needed_plain_tags, $disabled_definitions, $prospective_editor); $selected_plugins_plain_tags = self::selectCandidate($plugin_candidates_plain_tags, $still_needed_plain_tags, array_keys($provided_plain_tags->getAllowedElements())); // Select plugins for supporting the still needed attributes. - $plugin_candidates_attributes = self::getCandidates($provided, $still_needed_attributes, $disabled_definitions); + $prospective_editor_settings = $prospective_editor->getSettings(); + foreach (array_keys($selected_plugins_plain_tags) as $plugin_id) { + $plugin_definition = $this->pluginManager->getDefinition($plugin_id); + assert($plugin_definition instanceof CKEditor5PluginDefinition); + if ($plugin_definition->hasToolbarItems()) { + $prospective_editor_settings['toolbar']['items'] = [...$prospective_editor_settings['toolbar']['items'], ...array_keys($plugin_definition->getToolbarItems())]; + } + if ($plugin_definition->isConfigurable()) { + $prospective_editor_settings['plugins'][$plugin_id] = $this->pluginManager->createInstance($plugin_id)->defaultConfiguration(); + } + } + $prospective_editor->setSettings($prospective_editor_settings); + $plugin_candidates_attributes = self::getCandidates($provided, $still_needed_attributes, array_diff_key($disabled_definitions, $selected_plugins_plain_tags), $prospective_editor); $selected_plugins_attributes = self::selectCandidate($plugin_candidates_attributes, $still_needed, array_keys($provided->getAllowedElements())); // Combine the selection. @@ -858,8 +790,13 @@ private function addToolbarItemsToMatchHtmlElementsInFormat(FilterFormatInterfac $plugin_definition = $this->pluginManager->getDefinition($plugin_id); $label = $plugin_definition->label(); $plugins_enabled[] = $label; + [$net_new] = self::computeNetNewElementsForPlugin($provided, $still_needed, $plugin_definition); + // Track remaining elements/attributes that are still needed. + $still_needed = $still_needed->diff($net_new); + + // Fulfill the purpose of this method: generate the settings to add + // this plugin's toolbar item. if ($plugin_definition->hasToolbarItems()) { - [$net_new] = self::computeNetNewElementsForPlugin($provided, $still_needed, $plugin_definition); $editor_settings_to_update['toolbar']['items'] = array_merge($editor_settings_to_update['toolbar']['items'], array_keys($plugin_definition->getToolbarItems())); foreach ($reason_why_enabled as $attribute_name => $attribute_config) { // Plugin was selected for tag. @@ -884,9 +821,6 @@ private function addToolbarItemsToMatchHtmlElementsInFormat(FilterFormatInterfac } } } - - // Fewer attributes are still needed. - $still_needed = $still_needed->diff($net_new); } } $editor->setSettings($editor_settings_to_update); @@ -944,50 +878,4 @@ private function addDefaultSettingsForEnabledConfigurablePlugins(EditorInterface } } - /** - * Computes configuration for all enabled CKEditor 5 plugins with subsets. - * - * @param \Drupal\editor\EditorInterface $editor - * The text editor config entity to update. - * @param \Drupal\filter\FilterFormatInterface $text_format - * The text format for which to compute smart default settings. - */ - private function computeSubsetSettingForEnabledPluginsWithSubsets(EditorInterface $editor, FilterFormatInterface $text_format): void { - $settings = $editor->getSettings(); - $update_settings = FALSE; - $enabled_definitions = $this->pluginManager->getEnabledDefinitions($editor); - $configurable_subset_definitions = array_filter($enabled_definitions, function (CKEditor5PluginDefinition $definition): bool { - return is_a($definition->getClass(), CKEditor5PluginElementsSubsetInterface::class, TRUE); - }); - - foreach ($configurable_subset_definitions as $plugin_name => $definition) { - // Skip Source Editing as that has already been configured. - if ($plugin_name === 'ckeditor5_sourceEditing') { - continue; - } - - try { - $subset_configuration = $this->upgradePluginManager->computeCKEditor5PluginSubsetConfiguration($plugin_name, $text_format); - } - catch (\OutOfBoundsException $e) { - $messages[MessengerInterface::TYPE_WARNING][] = $this->t('The CKEditor 5 plugin %button has a configurable subset of elements, but does not have a known upgrade path to configure that subset to match your text format. Hence it is now using its default configuration.', [ - '%plugin' => $plugin_name, - ]); - continue; - } - if ($subset_configuration) { - $update_settings = TRUE; - assert(isset($settings['plugins'][$plugin_name])); - $default_configuration = $settings['plugins'][$plugin_name]; - // The subset configuration's key-value pairs must override those of the - // default configuration. - $settings['plugins'][$plugin_name] = $subset_configuration + $default_configuration; - } - } - - if ($update_settings) { - $editor->setSettings($settings); - } - } - } diff --git a/core/modules/ckeditor5/tests/modules/ckeditor4to5upgrade_plugin_test/ckeditor4to5upgrade_plugin_test.info.yml b/core/modules/ckeditor5/tests/modules/ckeditor4to5upgrade_plugin_test/ckeditor4to5upgrade_plugin_test.info.yml deleted file mode 100644 index e3c097d78514cab65bf8a37a3e495b3180db8f81..0000000000000000000000000000000000000000 --- a/core/modules/ckeditor5/tests/modules/ckeditor4to5upgrade_plugin_test/ckeditor4to5upgrade_plugin_test.info.yml +++ /dev/null @@ -1,6 +0,0 @@ -name: CKEditor 4 to 5 Upgrade plugin Test -type: module -description: "Provides test plugins for testing CKEditor 4 to 5 upgrade infrastructure." -package: Testing -dependencies: - - ckeditor5:ckeditor5 diff --git a/core/modules/ckeditor5/tests/modules/ckeditor4to5upgrade_plugin_test/ckeditor4to5upgrade_plugin_test.module b/core/modules/ckeditor5/tests/modules/ckeditor4to5upgrade_plugin_test/ckeditor4to5upgrade_plugin_test.module deleted file mode 100644 index cb99f7acc40008e8f081ea73669cdcd96343ba80..0000000000000000000000000000000000000000 --- a/core/modules/ckeditor5/tests/modules/ckeditor4to5upgrade_plugin_test/ckeditor4to5upgrade_plugin_test.module +++ /dev/null @@ -1,51 +0,0 @@ -<?php - -/** - * @file - * Implements hooks for the CKEditor 4 to 5 Upgrade plugin Test module. - */ - -declare(strict_types = 1); - -/** - * Implements hook_ckeditor4to5upgrade_plugin_info_alter(). - */ -function ckeditor4to5upgrade_plugin_test_ckeditor4to5upgrade_plugin_info_alter(array &$plugin_definitions): void { - switch (\Drupal::state()->get('ckeditor4to5upgrade_plugin_test')) { - case 'duplicate_button': - $plugin_definitions['foo'] = array_intersect_key($plugin_definitions['core'], ['cke4_buttons' => TRUE]); - break; - - case 'duplicate_plugin_settings': - $plugin_definitions['foo'] = array_intersect_key($plugin_definitions['core'], ['cke4_plugin_settings' => TRUE]); - break; - - case 'duplicate_subset': - $plugin_definitions['foo'] = array_intersect_key($plugin_definitions['core'], ['cke5_plugin_elements_subset_configuration' => TRUE]); - break; - - case 'lying_button': - $plugin_definitions['foo'] = [ - 'cke4_buttons' => ['foo'], - 'class' => $plugin_definitions['core']['class'], - ]; - break; - - case 'lying_plugin_settings': - $plugin_definitions['foo'] = [ - 'cke4_plugin_settings' => ['foo'], - 'class' => $plugin_definitions['core']['class'], - ]; - break; - - case 'lying_subset': - $plugin_definitions['foo'] = [ - 'cke5_plugin_elements_subset_configuration' => ['foo'], - 'class' => $plugin_definitions['core']['class'], - ]; - break; - - default: - throw new \LogicException(); - } -} diff --git a/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5AllowedTagsTest.php b/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5AllowedTagsTest.php index 5cbb823140a248ddc4526fb2ce953d43481e9940..65db1989a6497068867f2b4c9e3494c73c2351ba 100644 --- a/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5AllowedTagsTest.php +++ b/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5AllowedTagsTest.php @@ -52,7 +52,7 @@ class CKEditor5AllowedTagsTest extends CKEditor5TestBase { * * @var string */ - protected $defaultElementsAfterUpdatingToCkeditor5 = '<br> <p> <h2 id="jump-*"> <h3 id> <h4 id> <h5 id> <h6 id> <cite> <dl> <dt> <dd> <a hreflang href> <blockquote cite> <ul type> <ol type="1 A I" start> <strong> <em> <code> <li>'; + protected $defaultElementsAfterUpdatingToCkeditor5 = '<br> <p> <h2 id="jump-*"> <h3 id> <h4 id> <h5 id> <h6 id> <cite> <dl> <dt> <dd> <a hreflang href> <blockquote cite> <ul type> <ol type="1 A I" reversed start> <strong> <em> <code> <li>'; /** * Test enabling CKEditor 5 in a way that triggers validation. diff --git a/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditorStylesheetsWarningTest.php b/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditorStylesheetsWarningTest.php deleted file mode 100644 index ee42404ae02db0169ceec6bd75f78708d03c92dd..0000000000000000000000000000000000000000 --- a/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditorStylesheetsWarningTest.php +++ /dev/null @@ -1,75 +0,0 @@ -<?php - -declare(strict_types=1); - -namespace Drupal\Tests\ckeditor5\FunctionalJavascript; - -// cspell:ignore subtheming - -/** - * Tests warnings when ckeditor_stylesheets do not have CKEditor 5 equivalents. - * - * @group ckeditor5 - * @internal - */ -class CKEditorStylesheetsWarningTest extends CKEditor5TestBase { - - /** - * {@inheritdoc} - */ - protected function setUp(): void { - parent::setUp(); - } - - /** - * Installs and enables themes for testing. - * - * @param string $theme - * The theme to enable. - */ - public function installThemeThatTriggersWarning($theme) { - $theme_installer = \Drupal::service('theme_installer'); - $theme_installer->install([$theme]); - $this->config('system.theme')->set('default', $theme)->save(); - $theme_installer->install(['stark']); - $this->config('system.theme')->set('admin', 'stark')->save(); - \Drupal::service('theme_handler')->refreshInfo(); - } - - /** - * Test the ckeditor_stylesheets warning in the filter UI. - * - * @dataProvider providerTestWarningFilterUI - */ - public function testWarningFilterUi($theme, $expected_warning) { - $page = $this->getSession()->getPage(); - $assert_session = $this->assertSession(); - $this->addNewTextFormat($page, $assert_session); - $this->drupalGet('admin/config/content/formats/manage/ckeditor5'); - - $assert_session->pageTextNotContains($expected_warning); - $this->installThemeThatTriggersWarning($theme); - $this->drupalGet('admin/config/content/formats/manage/ckeditor5'); - $this->assertTrue($assert_session->waitForText($expected_warning)); - } - - /** - * Data provider for testWarningFilterUI(). - * - * @return string[][] - * An array with the theme to enable and the warning message to check. - */ - public function providerTestWarningFilterUi() { - return [ - 'single theme' => [ - 'theme' => 'test_ckeditor_stylesheets_without_5', - 'expected_warning' => 'The No setting for CKEditor 5 stylesheets theme has ckeditor_stylesheets configured without a corresponding ckeditor5-stylesheets configuration. See the change record for details.', - ], - 'with base theme' => [ - 'theme' => 'test_subtheming_ckeditor_stylesheets_without_5', - 'expected_warning' => 'The No setting for CKEditor 5 stylesheets here or subtheme and No setting for CKEditor 5 stylesheets themes have ckeditor_stylesheets configured, but without corresponding ckeditor5-stylesheets configurations. See the change record for details.', - ], - ]; - } - -} diff --git a/core/modules/ckeditor5/tests/src/Kernel/SmartDefaultSettingsTest.php b/core/modules/ckeditor5/tests/src/Kernel/SmartDefaultSettingsTest.php index 6fe3d0e48ced96fcb3dcebcc420f488dd00a92a3..9404a81ba8e481590c77580a4c996d4617ea0f37 100644 --- a/core/modules/ckeditor5/tests/src/Kernel/SmartDefaultSettingsTest.php +++ b/core/modules/ckeditor5/tests/src/Kernel/SmartDefaultSettingsTest.php @@ -73,7 +73,7 @@ class SmartDefaultSettingsTest extends KernelTestBase { 'editor', 'filter', 'user', - // For being able to test media_embed + Media button in CKE4/CKE5. + // For being able to test media_embed + Media button in CKE5. 'media', 'media_library', 'views', @@ -326,51 +326,6 @@ protected function setUp(): void { ], ])->save(); - FilterFormat::create([ - 'format' => 'cke4_plugins_with_settings', - 'name' => 'All CKEditor 4 core plugins with settings', - ])->save(); - Editor::create([ - 'format' => 'cke4_plugins_with_settings', - 'editor' => 'ckeditor', - 'settings' => [ - 'toolbar' => [ - 'rows' => [ - 0 => [ - [ - 'name' => 'Buttons with settings', - 'items' => [ - 'Language', - 'Styles', - // Blockquote does not have settings. It's present only to - // support an additional tag, to test realistic styles. - 'Blockquote', - ], - ], - [ - 'name' => 'Button without upgrade path', - 'items' => [ - 'Llama', - ], - ], - ], - ], - ], - 'plugins' => [ - 'language' => [ - 'language_list' => 'all', - ], - 'stylescombo' => [ - 'styles' => "p.callout|Callout\r\nblockquote.interesting.highlighted|Interesting & highlighted quote\n\nblockquote.famous | Famous\n", - ], - // Plugin setting without upgrade path. - 'llama_contextual_and_button' => [ - 'ultra_llama_mode' => TRUE, - ], - ], - ], - ])->save(); - FilterFormat::create([ 'format' => 'cke4_stylescombo_span', 'name' => 'A CKEditor 4 configured to have span styles', @@ -406,72 +361,6 @@ protected function setUp(): void { ], ], ])->save(); - - FilterFormat::create([ - 'format' => 'cke4_contrib_plugins_now_in_core', - 'name' => 'All CKEditor 4 contrib plugins now in core', - ])->save(); - Editor::create([ - 'format' => 'cke4_contrib_plugins_now_in_core', - 'editor' => 'ckeditor', - 'settings' => [ - 'toolbar' => [ - 'rows' => [ - 0 => [ - [ - 'name' => 'Contributed modules providing buttons without settings', - 'items' => [ - // @see https://www.drupal.org/project/codetag - 'Code', - ], - ], - ], - 1 => [ - [ - 'name' => 'Contributed modules providing buttons with settings', - 'items' => [ - // @see https://www.drupal.org/project/codesnippet - 'CodeSnippet', - ], - ], - ], - ], - ], - 'plugins' => [ - 'codesnippet' => [ - 'highlight_style' => 'arta', - 'highlight_languages' => [ - 'cs' => 'cs', - 'cpp' => 'cpp', - 'coffeescript' => 'coffeescript', - 'css' => 'css', - 'diff' => 'diff', - 'html' => 'html', - 'http' => 'http', - 'ini' => 'ini', - 'java' => 'java', - 'javascript' => 'javascript', - 'json' => 'json', - 'makefile' => 'makefile', - 'markdown' => 'markdown', - 'nginx' => 'nginx', - 'objectivec' => 'objectivec', - 'perl' => 'perl', - 'php' => 'php', - 'python' => 'python', - 'ruby' => 'ruby', - 'sql' => 'sql', - 'vbscript' => 'vbscript', - 'xhtml' => 'xhtml', - 'xml' => 'xml', - // These 2 languages have been disabled. - 'apache' => 0, - 'bash' => 0, - ], - ], - ], - ], - ])->save(); } /** @@ -657,25 +546,21 @@ public static function provider() { 'expected_ckeditor5_settings' => [ 'toolbar' => [ 'items' => [ - // Items based on toolbar items from prior config. + // Default toolbar items. + 'heading', 'bold', 'italic', '|', + // Items added based on "allowed tags" config. 'link', - '|', + 'blockQuote', + 'code', 'bulletedList', 'numberedList', - '|', - 'blockQuote', 'drupalInsertImage', - '|', - 'heading', + // Because additional tags need to be allowed to achieve a superset. '|', 'sourceEditing', - // Items added based on "allowed tags" config. - '|', - // The 'code' button added because <code> is allowed. - 'code', ], ], 'plugins' => [ @@ -693,7 +578,7 @@ public static function provider() { ], 'ckeditor5_list' => [ 'properties' => [ - 'reversed' => FALSE, + 'reversed' => TRUE, 'startIndex' => TRUE, ], 'multiBlock' => TRUE, @@ -718,11 +603,11 @@ public static function provider() { ], ], ], - 'expected_superset' => '', + 'expected_superset' => '<ol reversed>', 'expected_fundamental_compatibility_violations' => [], 'expected_db_logs' => [ 'status' => [ - 'The CKEditor 5 migration enabled the following plugins to support tags that are allowed by the <em class="placeholder">Basic HTML</em> text format: <em class="placeholder">Code (for tags: <code>)</em>. The text format must be saved to make these changes active.', + 'The CKEditor 5 migration enabled the following plugins to support tags that are allowed by the <em class="placeholder">Basic HTML</em> text format: <em class="placeholder">Link (for tags: <a>) Block quote (for tags: <blockquote>) Code (for tags: <code>) List (for tags: <ul><ol><li>) Image (for tags: <img>)</em>. The text format must be saved to make these changes active.', 'The following tags were permitted by the <em class="placeholder">Basic HTML</em> text format\'s filter configuration, but no plugin was available that supports them. To ensure the tags remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <cite> <dl> <dt> <dd> <span>. The text format must be saved to make these changes active.', ], ], @@ -739,65 +624,90 @@ public static function provider() { ], 'expected_messages' => [ 'status' => [ - 'To maintain the capabilities of this text format, <a target="_blank" href="/admin/help/ckeditor5#migration-settings">the CKEditor 5 migration</a> did the following: Enabled these plugins: (<em class="placeholder">Code</em>). Added these tags/attributes to the Source Editing Plugin\'s <a target="_blank" href="/admin/help/ckeditor5#source-editing">Manually editable HTML tags</a> setting: <cite> <dl> <dt> <dd> <span> <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>. Additional details are available in your logs.', + 'To maintain the capabilities of this text format, <a target="_blank" href="/admin/help/ckeditor5#migration-settings">the CKEditor 5 migration</a> did the following: Enabled these plugins: (<em class="placeholder">Link, Block quote, Code, List, Image, Image Upload, Image align, Image caption</em>). Added these tags/attributes to the Source Editing Plugin\'s <a target="_blank" href="/admin/help/ckeditor5#source-editing">Manually editable HTML tags</a> setting: <cite> <dl> <dt> <dd> <span> <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>. Additional details are available in your logs.', + ], + 'warning' => [ + 'Updating to CKEditor 5 added support for some previously unsupported tags/attributes. A plugin introduced support for the following: This attribute: <em class="placeholder"> reversed (for <ol>)</em>; Additional details are available in your logs.', ], ], ] ); - yield "basic_html with filter_caption removed => disallows <img data-caption> => supported through sourceEditing (3 upgrade messages)" => NestedArray::mergeDeep( - $basic_html_test_case, - [ - 'filters_to_drop' => [ - 'filter_caption' => FALSE, - ], - 'expected_ckeditor5_settings' => [ - 'plugins' => [ - 'ckeditor5_sourceEditing' => [ - 'allowed_tags' => [ - '<img data-caption>', - ], - ], + yield "basic_html with filter_caption removed => disallows <img data-caption> => supported through sourceEditing (3 upgrade messages)" => [ + 'format_id' => 'basic_html', + 'filters_to_drop' => [ + 'filter_caption' => FALSE, + ], + 'expected_ckeditor5_settings' => [ + 'toolbar' => $basic_html_test_case['expected_ckeditor5_settings']['toolbar'], + 'plugins' => [ + 'ckeditor5_heading' => $basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_heading'], + 'ckeditor5_imageResize' => $basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_imageResize'], + 'ckeditor5_list' => $basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_list'], + 'ckeditor5_sourceEditing' => [ + 'allowed_tags' => array_merge( + array_slice($basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_sourceEditing']['allowed_tags'], 0, 9), + ['<img data-caption>'], + array_slice($basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_sourceEditing']['allowed_tags'], 9), + ), ], ], - 'expected_db_logs' => [ - 'status' => [ - 'As part of migrating to CKEditor 5, it was found that the <em class="placeholder">Basic HTML</em> text format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <img data-caption>. The text format must be saved to make these changes active.', - ], + ], + 'expected_superset' => $basic_html_test_case['expected_superset'], + 'expected_fundamental_compatibility_violations' => $basic_html_test_case['expected_fundamental_compatibility_violations'], + 'expected_db_logs' => [ + 'status' => [ + ...$basic_html_test_case['expected_db_logs']['status'], + 'As part of migrating to CKEditor 5, it was found that the <em class="placeholder">Basic HTML</em> text format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol type> <img data-caption> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>. The text format must be saved to make these changes active.', ], - 'expected_messages' => [ - 'status' => [ - 'To maintain the capabilities of this text format, <a target="_blank" href="/admin/help/ckeditor5#migration-settings">the CKEditor 5 migration</a> did the following: Enabled these plugins: (<em class="placeholder">Code</em>). Added these tags/attributes to the Source Editing Plugin\'s <a target="_blank" href="/admin/help/ckeditor5#source-editing">Manually editable HTML tags</a> setting: <cite> <dl> <dt> <dd> <span> <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <img data-caption>. Additional details are available in your logs.', - ], + ], + 'expected_messages' => [ + 'status' => [ + 'To maintain the capabilities of this text format, <a target="_blank" href="/admin/help/ckeditor5#migration-settings">the CKEditor 5 migration</a> did the following: Enabled these plugins: (<em class="placeholder">Link, Block quote, Code, List, Image, Image Upload, Image align</em>). Added these tags/attributes to the Source Editing Plugin\'s <a target="_blank" href="/admin/help/ckeditor5#source-editing">Manually editable HTML tags</a> setting: <cite> <dl> <dt> <dd> <span> <a hreflang> <blockquote cite> <ul type> <ol type> <img data-caption> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>. Additional details are available in your logs.', ], - ]); + 'warning' => [ + 'Updating to CKEditor 5 added support for some previously unsupported tags/attributes. A plugin introduced support for the following: This attribute: <em class="placeholder"> reversed (for <ol>)</em>; Additional details are available in your logs.', + ], + ], + ]; - yield "basic_html with filter_align removed => disallows <img data-align> => supported through sourceEditing (3 upgrade messages) " => NestedArray::mergeDeep( - $basic_html_test_case, - [ - 'filters_to_drop' => [ - 'filter_align' => FALSE, - ], - 'expected_ckeditor5_settings' => [ - 'plugins' => [ - 'ckeditor5_sourceEditing' => [ - 'allowed_tags' => [ - '<img data-align>', - ], - ], + yield "basic_html with filter_align removed => disallows <img data-align> => supported through sourceEditing (3 upgrade messages) " => [ + 'format_id' => 'basic_html', + 'filters_to_drop' => [ + 'filter_align' => FALSE, + ], + 'expected_ckeditor5_settings' => [ + 'toolbar' => $basic_html_test_case['expected_ckeditor5_settings']['toolbar'], + 'plugins' => [ + 'ckeditor5_heading' => $basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_heading'], + 'ckeditor5_imageResize' => $basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_imageResize'], + 'ckeditor5_list' => $basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_list'], + 'ckeditor5_sourceEditing' => [ + 'allowed_tags' => array_merge( + array_slice($basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_sourceEditing']['allowed_tags'], 0, 9), + ['<img data-align>'], + array_slice($basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_sourceEditing']['allowed_tags'], 9), + ), ], ], - 'expected_db_logs' => [ - 'status' => [ - 'As part of migrating to CKEditor 5, it was found that the <em class="placeholder">Basic HTML</em> text format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <img data-align>. The text format must be saved to make these changes active.', - ], + ], + 'expected_superset' => $basic_html_test_case['expected_superset'], + 'expected_fundamental_compatibility_violations' => $basic_html_test_case['expected_fundamental_compatibility_violations'], + 'expected_db_logs' => [ + 'status' => [ + ...$basic_html_test_case['expected_db_logs']['status'], + 'As part of migrating to CKEditor 5, it was found that the <em class="placeholder">Basic HTML</em> text format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol type> <img data-align> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>. The text format must be saved to make these changes active.', ], - 'expected_messages' => [ - 'status' => [ - 'To maintain the capabilities of this text format, <a target="_blank" href="/admin/help/ckeditor5#migration-settings">the CKEditor 5 migration</a> did the following: Enabled these plugins: (<em class="placeholder">Code</em>). Added these tags/attributes to the Source Editing Plugin\'s <a target="_blank" href="/admin/help/ckeditor5#source-editing">Manually editable HTML tags</a> setting: <cite> <dl> <dt> <dd> <span> <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <img data-align>. Additional details are available in your logs.', - ], + ], + 'expected_messages' => [ + 'status' => [ + 'To maintain the capabilities of this text format, <a target="_blank" href="/admin/help/ckeditor5#migration-settings">the CKEditor 5 migration</a> did the following: Enabled these plugins: (<em class="placeholder">Link, Block quote, Code, List, Image, Image Upload, Image caption</em>). Added these tags/attributes to the Source Editing Plugin\'s <a target="_blank" href="/admin/help/ckeditor5#source-editing">Manually editable HTML tags</a> setting: <cite> <dl> <dt> <dd> <span> <a hreflang> <blockquote cite> <ul type> <ol type> <img data-align> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>. Additional details are available in your logs.', ], - ]); + 'warning' => [ + 'Updating to CKEditor 5 added support for some previously unsupported tags/attributes. A plugin introduced support for the following: This attribute: <em class="placeholder"> reversed (for <ol>)</em>; Additional details are available in your logs.', + ], + ], + ]; yield "basic_html_without_image_uploads can be switched to CKEditor 5 without problems, <img data-entity-type data-entity-uuid> support is retained via sourceEditing" => [ 'format_id' => 'basic_html_without_image_uploads', @@ -810,8 +720,9 @@ public static function provider() { 'ckeditor5_list' => $basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_list'], 'ckeditor5_sourceEditing' => [ 'allowed_tags' => array_merge( - $basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_sourceEditing']['allowed_tags'], + array_slice($basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_sourceEditing']['allowed_tags'], 0, 9), ['<img data-entity-type data-entity-uuid>'], + array_slice($basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_sourceEditing']['allowed_tags'], 9), ), ], ], @@ -820,19 +731,22 @@ public static function provider() { 'expected_fundamental_compatibility_violations' => $basic_html_test_case['expected_fundamental_compatibility_violations'], 'expected_db_logs' => [ 'status' => [ - 'The CKEditor 5 migration enabled the following plugins to support tags that are allowed by the <em class="placeholder">Basic HTML (without image uploads)</em> text format: <em class="placeholder">Code (for tags: <code>)</em>. The text format must be saved to make these changes active.', + 'The CKEditor 5 migration enabled the following plugins to support tags that are allowed by the <em class="placeholder">Basic HTML (without image uploads)</em> text format: <em class="placeholder">Link (for tags: <a>) Block quote (for tags: <blockquote>) Code (for tags: <code>) List (for tags: <ul><ol><li>) Image (for tags: <img>)</em>. The text format must be saved to make these changes active.', 'The following tags were permitted by the <em class="placeholder">Basic HTML (without image uploads)</em> text format\'s filter configuration, but no plugin was available that supports them. To ensure the tags remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <cite> <dl> <dt> <dd> <span>. The text format must be saved to make these changes active.', - 'As part of migrating to CKEditor 5, it was found that the <em class="placeholder">Basic HTML (without image uploads)</em> text format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <img data-entity-type data-entity-uuid>. The text format must be saved to make these changes active.', + 'As part of migrating to CKEditor 5, it was found that the <em class="placeholder">Basic HTML (without image uploads)</em> text format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol type> <img data-entity-type data-entity-uuid> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>. The text format must be saved to make these changes active.', ], ], 'expected_messages' => [ 'status' => [ - 'To maintain the capabilities of this text format, <a target="_blank" href="/admin/help/ckeditor5#migration-settings">the CKEditor 5 migration</a> did the following: Enabled these plugins: (<em class="placeholder">Code</em>). Added these tags/attributes to the Source Editing Plugin\'s <a target="_blank" href="/admin/help/ckeditor5#source-editing">Manually editable HTML tags</a> setting: <cite> <dl> <dt> <dd> <span> <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <img data-entity-type data-entity-uuid>. Additional details are available in your logs.', + 'To maintain the capabilities of this text format, <a target="_blank" href="/admin/help/ckeditor5#migration-settings">the CKEditor 5 migration</a> did the following: Enabled these plugins: (<em class="placeholder">Link, Block quote, Code, List, Image, Image align, Image caption</em>). Added these tags/attributes to the Source Editing Plugin\'s <a target="_blank" href="/admin/help/ckeditor5#source-editing">Manually editable HTML tags</a> setting: <cite> <dl> <dt> <dd> <span> <a hreflang> <blockquote cite> <ul type> <ol type> <img data-entity-type data-entity-uuid> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>. Additional details are available in your logs.', + ], + 'warning' => [ + 'Updating to CKEditor 5 added support for some previously unsupported tags/attributes. A plugin introduced support for the following: This attribute: <em class="placeholder"> reversed (for <ol>)</em>; Additional details are available in your logs.', ], ], ]; - yield "basic_html_without_h4_h6 can be switched to CKEditor 5 without problems, heading configuration computed automatically" => [ + yield "basic_html_without_h4_h6 can be switched to CKEditor 5 without problems" => [ 'format_id' => 'basic_html_without_h4_h6', 'filters_to_drop' => $basic_html_test_case['filters_to_drop'], 'expected_ckeditor5_settings' => [ @@ -842,13 +756,15 @@ public static function provider() { 'enabled_headings' => [ 'heading2', 'heading3', + 'heading4', 'heading5', + 'heading6', ], ], 'ckeditor5_imageResize' => ['allow_resize' => TRUE], 'ckeditor5_list' => [ 'properties' => [ - 'reversed' => FALSE, + 'reversed' => TRUE, 'startIndex' => TRUE, ], 'multiBlock' => TRUE, @@ -861,23 +777,26 @@ public static function provider() { ], ], ], - 'expected_superset' => $basic_html_test_case['expected_superset'], + 'expected_superset' => '<h4> <h6> ' . $basic_html_test_case['expected_superset'], 'expected_fundamental_compatibility_violations' => $basic_html_test_case['expected_fundamental_compatibility_violations'], 'expected_db_logs' => [ 'status' => [ - 'The CKEditor 5 migration enabled the following plugins to support tags that are allowed by the <em class="placeholder">Basic HTML (without H4 and H6)</em> text format: <em class="placeholder">Code (for tags: <code>)</em>. The text format must be saved to make these changes active.', + 'The CKEditor 5 migration enabled the following plugins to support tags that are allowed by the <em class="placeholder">Basic HTML (without H4 and H6)</em> text format: <em class="placeholder">Link (for tags: <a>) Block quote (for tags: <blockquote>) Code (for tags: <code>) List (for tags: <ul><ol><li>) Image (for tags: <img>)</em>. The text format must be saved to make these changes active.', 'The following tags were permitted by the <em class="placeholder">Basic HTML (without H4 and H6)</em> text format\'s filter configuration, but no plugin was available that supports them. To ensure the tags remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <cite> <dl> <dt> <dd> <span>. The text format must be saved to make these changes active.', 'As part of migrating to CKEditor 5, it was found that the <em class="placeholder">Basic HTML (without H4 and H6)</em> text format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h5 id>. The text format must be saved to make these changes active.', ], ], 'expected_messages' => [ 'status' => [ - 'To maintain the capabilities of this text format, <a target="_blank" href="/admin/help/ckeditor5#migration-settings">the CKEditor 5 migration</a> did the following: Enabled these plugins: (<em class="placeholder">Code</em>). Added these tags/attributes to the Source Editing Plugin\'s <a target="_blank" href="/admin/help/ckeditor5#source-editing">Manually editable HTML tags</a> setting: <cite> <dl> <dt> <dd> <span> <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h5 id>. Additional details are available in your logs.', + 'To maintain the capabilities of this text format, <a target="_blank" href="/admin/help/ckeditor5#migration-settings">the CKEditor 5 migration</a> did the following: Enabled these plugins: (<em class="placeholder">Link, Block quote, Code, List, Image, Image Upload, Image align, Image caption</em>). Added these tags/attributes to the Source Editing Plugin\'s <a target="_blank" href="/admin/help/ckeditor5#source-editing">Manually editable HTML tags</a> setting: <cite> <dl> <dt> <dd> <span> <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h5 id>. Additional details are available in your logs.', + ], + 'warning' => [ + 'Updating to CKEditor 5 added support for some previously unsupported tags/attributes. A plugin introduced support for the following: The tags <em class="placeholder"><h4>, <h6></em>; This attribute: <em class="placeholder"> reversed (for <ol>)</em>; Additional details are available in your logs.', ], ], ]; - yield "basic_html_with_h1 can be switched to CKEditor 5 without problems, heading configuration computed automatically" => [ + yield "basic_html_with_h1 can be switched to CKEditor 5 without problems" => [ 'format_id' => 'basic_html_with_h1', 'filters_to_drop' => $basic_html_test_case['filters_to_drop'], 'expected_ckeditor5_settings' => [ @@ -885,7 +804,6 @@ public static function provider() { 'plugins' => [ 'ckeditor5_heading' => [ 'enabled_headings' => [ - 'heading1', 'heading2', 'heading3', 'heading4', @@ -896,13 +814,17 @@ public static function provider() { 'ckeditor5_imageResize' => ['allow_resize' => TRUE], 'ckeditor5_list' => [ 'properties' => [ - 'reversed' => FALSE, + 'reversed' => TRUE, 'startIndex' => TRUE, ], 'multiBlock' => TRUE, ], 'ckeditor5_sourceEditing' => [ - 'allowed_tags' => $basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_sourceEditing']['allowed_tags'], + 'allowed_tags' => array_merge( + array_slice($basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_sourceEditing']['allowed_tags'], 0, 5), + ['<h1>'], + array_slice($basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_sourceEditing']['allowed_tags'], 5), + ), ], ], ], @@ -910,33 +832,34 @@ public static function provider() { 'expected_fundamental_compatibility_violations' => $basic_html_test_case['expected_fundamental_compatibility_violations'], 'expected_db_logs' => [ 'status' => [ - 'The CKEditor 5 migration enabled the following plugins to support tags that are allowed by the <em class="placeholder">Basic HTML (with <h1>)</em> text format: <em class="placeholder">Code (for tags: <code>)</em>. The text format must be saved to make these changes active.', - 'The following tags were permitted by the <em class="placeholder">Basic HTML (with <h1>)</em> text format\'s filter configuration, but no plugin was available that supports them. To ensure the tags remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <cite> <dl> <dt> <dd> <span>. The text format must be saved to make these changes active.', + 'The CKEditor 5 migration enabled the following plugins to support tags that are allowed by the <em class="placeholder">Basic HTML (with <h1>)</em> text format: <em class="placeholder">Link (for tags: <a>) Block quote (for tags: <blockquote>) Code (for tags: <code>) List (for tags: <ul><ol><li>) Image (for tags: <img>)</em>. The text format must be saved to make these changes active.', + 'The following tags were permitted by the <em class="placeholder">Basic HTML (with <h1>)</em> text format\'s filter configuration, but no plugin was available that supports them. To ensure the tags remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <cite> <dl> <dt> <dd> <span> <h1>. The text format must be saved to make these changes active.', 'As part of migrating to CKEditor 5, it was found that the <em class="placeholder">Basic HTML (with <h1>)</em> text format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>. The text format must be saved to make these changes active.', ], ], 'expected_messages' => [ 'status' => [ - 'To maintain the capabilities of this text format, <a target="_blank" href="/admin/help/ckeditor5#migration-settings">the CKEditor 5 migration</a> did the following: Enabled these plugins: (<em class="placeholder">Code</em>). Added these tags/attributes to the Source Editing Plugin\'s <a target="_blank" href="/admin/help/ckeditor5#source-editing">Manually editable HTML tags</a> setting: <cite> <dl> <dt> <dd> <span> <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>. Additional details are available in your logs.', + 'To maintain the capabilities of this text format, <a target="_blank" href="/admin/help/ckeditor5#migration-settings">the CKEditor 5 migration</a> did the following: Enabled these plugins: (<em class="placeholder">Link, Block quote, Code, List, Image, Image Upload, Image align, Image caption</em>). Added these tags/attributes to the Source Editing Plugin\'s <a target="_blank" href="/admin/help/ckeditor5#source-editing">Manually editable HTML tags</a> setting: <cite> <dl> <dt> <dd> <span> <h1> <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>. Additional details are available in your logs.', + ], + 'warning' => [ + 'Updating to CKEditor 5 added support for some previously unsupported tags/attributes. A plugin introduced support for the following: This attribute: <em class="placeholder"> reversed (for <ol>)</em>; Additional details are available in your logs.', ], ], ]; - yield "basic_html_without_headings can be switched to CKEditor 5 without problems, heading configuration computed automatically" => [ + yield "basic_html_without_headings can be switched to CKEditor 5 without problems" => [ 'format_id' => 'basic_html_without_headings', 'filters_to_drop' => $basic_html_test_case['filters_to_drop'], 'expected_ckeditor5_settings' => [ 'toolbar' => [ - 'items' => array_merge( - array_slice($basic_html_test_case['expected_ckeditor5_settings']['toolbar']['items'], 0, 10), - array_slice($basic_html_test_case['expected_ckeditor5_settings']['toolbar']['items'], 12), - ), + 'items' => $basic_html_test_case['expected_ckeditor5_settings']['toolbar']['items'], ], 'plugins' => [ + 'ckeditor5_heading' => $basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_heading'], 'ckeditor5_imageResize' => ['allow_resize' => TRUE], 'ckeditor5_list' => [ 'properties' => [ - 'reversed' => FALSE, + 'reversed' => TRUE, 'startIndex' => TRUE, ], 'multiBlock' => TRUE, @@ -949,30 +872,34 @@ public static function provider() { ], ], ], - 'expected_superset' => $basic_html_test_case['expected_superset'], + 'expected_superset' => '<h2> <h3> <h4> <h5> <h6> ' . $basic_html_test_case['expected_superset'], 'expected_fundamental_compatibility_violations' => $basic_html_test_case['expected_fundamental_compatibility_violations'], 'expected_db_logs' => [ 'status' => [ - 'The CKEditor 5 migration enabled the following plugins to support tags that are allowed by the <em class="placeholder">Basic HTML (without H*)</em> text format: <em class="placeholder">Code (for tags: <code>)</em>. The text format must be saved to make these changes active.', + 'The CKEditor 5 migration enabled the following plugins to support tags that are allowed by the <em class="placeholder">Basic HTML (without H*)</em> text format: <em class="placeholder">Link (for tags: <a>) Block quote (for tags: <blockquote>) Code (for tags: <code>) List (for tags: <ul><ol><li>) Image (for tags: <img>)</em>. The text format must be saved to make these changes active.', 'The following tags were permitted by the <em class="placeholder">Basic HTML (without H*)</em> text format\'s filter configuration, but no plugin was available that supports them. To ensure the tags remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <cite> <dl> <dt> <dd> <span>. The text format must be saved to make these changes active.', 'As part of migrating to CKEditor 5, it was found that the <em class="placeholder">Basic HTML (without H*)</em> text format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol type>. The text format must be saved to make these changes active.', ], ], 'expected_messages' => [ 'status' => [ - 'To maintain the capabilities of this text format, <a target="_blank" href="/admin/help/ckeditor5#migration-settings">the CKEditor 5 migration</a> did the following: Enabled these plugins: (<em class="placeholder">Code</em>). Added these tags/attributes to the Source Editing Plugin\'s <a target="_blank" href="/admin/help/ckeditor5#source-editing">Manually editable HTML tags</a> setting: <cite> <dl> <dt> <dd> <span> <a hreflang> <blockquote cite> <ul type> <ol type>. Additional details are available in your logs.', + 'To maintain the capabilities of this text format, <a target="_blank" href="/admin/help/ckeditor5#migration-settings">the CKEditor 5 migration</a> did the following: Enabled these plugins: (<em class="placeholder">Link, Block quote, Code, List, Image, Image Upload, Image align, Image caption</em>). Added these tags/attributes to the Source Editing Plugin\'s <a target="_blank" href="/admin/help/ckeditor5#source-editing">Manually editable HTML tags</a> setting: <cite> <dl> <dt> <dd> <span> <a hreflang> <blockquote cite> <ul type> <ol type>. Additional details are available in your logs.', + ], + 'warning' => [ + 'Updating to CKEditor 5 added support for some previously unsupported tags/attributes. A plugin introduced support for the following: The tags <em class="placeholder"><h2>, <h3>, <h4>, <h5>, <h6></em>; This attribute: <em class="placeholder"> reversed (for <ol>)</em>; Additional details are available in your logs.', ], ], ]; - yield "basic_html_with_pre can be switched to CKEditor 5 without problems, heading configuration computed automatically" => [ + yield "basic_html_with_pre can be switched to CKEditor 5 without problems" => [ 'format_id' => 'basic_html_with_pre', 'filters_to_drop' => $basic_html_test_case['filters_to_drop'], 'expected_ckeditor5_settings' => [ 'toolbar' => [ 'items' => array_merge( - $basic_html_test_case['expected_ckeditor5_settings']['toolbar']['items'], + array_slice($basic_html_test_case['expected_ckeditor5_settings']['toolbar']['items'], 0, 10), ['codeBlock'], + array_slice($basic_html_test_case['expected_ckeditor5_settings']['toolbar']['items'], -2), ), ], 'plugins' => [ @@ -996,39 +923,40 @@ public static function provider() { ], ] + $basic_html_test_case['expected_ckeditor5_settings']['plugins'], ], - 'expected_superset' => '<code class="language-*">', + 'expected_superset' => '<ol reversed> <code class="language-*">', 'expected_fundamental_compatibility_violations' => $basic_html_test_case['expected_fundamental_compatibility_violations'], 'expected_db_logs' => [ 'status' => [ - 'The CKEditor 5 migration enabled the following plugins to support tags that are allowed by the <em class="placeholder">Basic HTML (with <pre>)</em> text format: <em class="placeholder">Code (for tags: <code>) Code Block (for tags: <pre>)</em>. The text format must be saved to make these changes active.', + 'The CKEditor 5 migration enabled the following plugins to support tags that are allowed by the <em class="placeholder">Basic HTML (with <pre>)</em> text format: <em class="placeholder">Link (for tags: <a>) Block quote (for tags: <blockquote>) Code (for tags: <code>) List (for tags: <ul><ol><li>) Image (for tags: <img>) Code Block (for tags: <pre>)</em>. The text format must be saved to make these changes active.', str_replace('Basic HTML', 'Basic HTML (with <pre>)', $basic_html_test_case['expected_db_logs']['status'][1]), 'As part of migrating to CKEditor 5, it was found that the <em class="placeholder">Basic HTML (with <pre>)</em> text format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>. The text format must be saved to make these changes active.', ], ], 'expected_messages' => [ 'status' => [ - 'To maintain the capabilities of this text format, <a target="_blank" href="/admin/help/ckeditor5#migration-settings">the CKEditor 5 migration</a> did the following: Enabled these plugins: (<em class="placeholder">Code, Code Block</em>). Added these tags/attributes to the Source Editing Plugin\'s <a target="_blank" href="/admin/help/ckeditor5#source-editing">Manually editable HTML tags</a> setting: <cite> <dl> <dt> <dd> <span> <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>. Additional details are available in your logs.', + 'To maintain the capabilities of this text format, <a target="_blank" href="/admin/help/ckeditor5#migration-settings">the CKEditor 5 migration</a> did the following: Enabled these plugins: (<em class="placeholder">Link, Block quote, Code, List, Image, Code Block, Image Upload, Image align, Image caption</em>). Added these tags/attributes to the Source Editing Plugin\'s <a target="_blank" href="/admin/help/ckeditor5#source-editing">Manually editable HTML tags</a> setting: <cite> <dl> <dt> <dd> <span> <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>. Additional details are available in your logs.', ], 'warning' => [ - 'Updating to CKEditor 5 added support for some previously unsupported tags/attributes. A plugin introduced support for the following: This attribute: <em class="placeholder"> class (for <code>)</em>; Additional details are available in your logs.', + 'Updating to CKEditor 5 added support for some previously unsupported tags/attributes. A plugin introduced support for the following: These attributes: <em class="placeholder"> reversed (for <ol>), class (for <code>)</em>; Additional details are available in your logs.', ], ], ]; - yield "basic_html_with_alignable_p can be switched to CKEditor 5 without problems, align buttons added automatically" => [ + yield "basic_html_with_alignable_p can be switched to CKEditor 5 without problems, align buttons added automatically, but a superset of alignments is enabled" => [ 'format_id' => 'basic_html_with_alignable_p', 'filters_to_drop' => $basic_html_test_case['filters_to_drop'], 'expected_ckeditor5_settings' => [ 'toolbar' => [ 'items' => array_merge( - $basic_html_test_case['expected_ckeditor5_settings']['toolbar']['items'], + array_slice($basic_html_test_case['expected_ckeditor5_settings']['toolbar']['items'], 0, 10), ['alignment'], + array_slice($basic_html_test_case['expected_ckeditor5_settings']['toolbar']['items'], -2), ), ], 'plugins' => array_merge( [ 'ckeditor5_alignment' => [ - 'enabled_alignments' => ['center', 'justify'], + 'enabled_alignments' => ['center', 'justify', 'left', 'right'], ], ], $basic_html_test_case['expected_ckeditor5_settings']['plugins'], @@ -1041,16 +969,18 @@ public static function provider() { // allowed CKEditor 5 `$block` text container tags. // @todo When https://www.drupal.org/project/drupal/issues/3259367 // lands, none of the tags below should appear. - '<h2 class="text-align-center text-align-justify">', - '<h3 class="text-align-center text-align-justify">', - '<h4 class="text-align-center text-align-justify">', - '<h5 class="text-align-center text-align-justify">', - '<h6 class="text-align-center text-align-justify">', + '<p class="text-align-left text-align-right">', + '<h2 class="text-align-left text-align-center text-align-right text-align-justify">', + '<h3 class="text-align-left text-align-center text-align-right text-align-justify">', + '<h4 class="text-align-left text-align-center text-align-right text-align-justify">', + '<h5 class="text-align-left text-align-center text-align-right text-align-justify">', + '<h6 class="text-align-left text-align-center text-align-right text-align-justify">', + '<ol reversed>', ]), 'expected_fundamental_compatibility_violations' => $basic_html_test_case['expected_fundamental_compatibility_violations'], 'expected_db_logs' => [ 'status' => [ - 'The CKEditor 5 migration enabled the following plugins to support tags that are allowed by the <em class="placeholder">Basic HTML (with alignable paragraph support)</em> text format: <em class="placeholder">Code (for tags: <code>)</em>. The text format must be saved to make these changes active.', + 'The CKEditor 5 migration enabled the following plugins to support tags that are allowed by the <em class="placeholder">Basic HTML (with alignable paragraph support)</em> text format: <em class="placeholder">Link (for tags: <a>) Block quote (for tags: <blockquote>) Code (for tags: <code>) List (for tags: <ul><ol><li>) Image (for tags: <img>)</em>. The text format must be saved to make these changes active.', 'The following tags were permitted by the <em class="placeholder">Basic HTML (with alignable paragraph support)</em> text format\'s filter configuration, but no plugin was available that supports them. To ensure the tags remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <cite> <dl> <dt> <dd> <span>. The text format must be saved to make these changes active.', 'The CKEditor 5 migration process enabled the following plugins to support specific attributes that are allowed by the <em class="placeholder">Basic HTML (with alignable paragraph support)</em> text format: <em class="placeholder">Alignment ( for tag: <p> to support: class with value(s): text-align-center, text-align-justify)</em>.', 'As part of migrating to CKEditor 5, it was found that the <em class="placeholder">Basic HTML (with alignable paragraph support)</em> text format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>. The text format must be saved to make these changes active.', @@ -1058,24 +988,20 @@ public static function provider() { ], 'expected_messages' => [ 'status' => [ - 'To maintain the capabilities of this text format, <a target="_blank" href="/admin/help/ckeditor5#migration-settings">the CKEditor 5 migration</a> did the following: Enabled these plugins: (<em class="placeholder">Code, Alignment</em>). Added these tags/attributes to the Source Editing Plugin\'s <a target="_blank" href="/admin/help/ckeditor5#source-editing">Manually editable HTML tags</a> setting: <cite> <dl> <dt> <dd> <span> <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>. Additional details are available in your logs.', + 'To maintain the capabilities of this text format, <a target="_blank" href="/admin/help/ckeditor5#migration-settings">the CKEditor 5 migration</a> did the following: Enabled these plugins: (<em class="placeholder">Link, Block quote, Code, List, Image, Image Upload, Image align, Image caption, Alignment</em>). Added these tags/attributes to the Source Editing Plugin\'s <a target="_blank" href="/admin/help/ckeditor5#source-editing">Manually editable HTML tags</a> setting: <cite> <dl> <dt> <dd> <span> <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>. Additional details are available in your logs.', ], 'warning' => [ - 'Updating to CKEditor 5 added support for some previously unsupported tags/attributes. A plugin introduced support for the following: This attribute: <em class="placeholder"> class (for <h2>, <h3>, <h4>, <h5>, <h6>)</em>; Additional details are available in your logs.', + 'Updating to CKEditor 5 added support for some previously unsupported tags/attributes. A plugin introduced support for the following: These attributes: <em class="placeholder"> class (for <p>, <h2>, <h3>, <h4>, <h5>, <h6>), reversed (for <ol>)</em>; Additional details are available in your logs.', ], ], ]; - yield "basic_html with media_embed added (3 upgrade messages)" => [ + yield "basic_html with media_embed added (3 upgrade messages), but the drupalMedia toolbar item is not added automatically" => [ 'format_id' => 'basic_html_with_media_embed', 'filters_to_drop' => $basic_html_test_case['filters_to_drop'], 'expected_ckeditor5_settings' => [ 'toolbar' => [ - 'items' => array_merge( - array_slice($basic_html_test_case['expected_ckeditor5_settings']['toolbar']['items'], 0, 10), - ['drupalMedia'], - array_slice($basic_html_test_case['expected_ckeditor5_settings']['toolbar']['items'], 10), - ), + 'items' => $basic_html_test_case['expected_ckeditor5_settings']['toolbar']['items'], ], 'plugins' => array_merge($basic_html_test_case['expected_ckeditor5_settings']['plugins'], ['media_media' => ['allow_view_mode_override' => FALSE]]), ], @@ -1083,80 +1009,105 @@ public static function provider() { 'expected_fundamental_compatibility_violations' => $basic_html_test_case['expected_fundamental_compatibility_violations'], 'expected_db_logs' => [ 'status' => [ - 'The CKEditor 5 migration enabled the following plugins to support tags that are allowed by the <em class="placeholder">Basic HTML (with Media Embed support)</em> text format: <em class="placeholder">Code (for tags: <code>)</em>. The text format must be saved to make these changes active.', + 'The CKEditor 5 migration enabled the following plugins to support tags that are allowed by the <em class="placeholder">Basic HTML (with Media Embed support)</em> text format: <em class="placeholder">Link (for tags: <a>) Block quote (for tags: <blockquote>) Code (for tags: <code>) List (for tags: <ul><ol><li>) Image (for tags: <img>)</em>. The text format must be saved to make these changes active.', 'The following tags were permitted by the <em class="placeholder">Basic HTML (with Media Embed support)</em> text format\'s filter configuration, but no plugin was available that supports them. To ensure the tags remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <cite> <dl> <dt> <dd> <span>. The text format must be saved to make these changes active.', 'As part of migrating to CKEditor 5, it was found that the <em class="placeholder">Basic HTML (with Media Embed support)</em> text format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>. The text format must be saved to make these changes active.', ], ], 'expected_messages' => [ 'status' => [ - 'To maintain the capabilities of this text format, <a target="_blank" href="/admin/help/ckeditor5#migration-settings">the CKEditor 5 migration</a> did the following: Enabled these plugins: (<em class="placeholder">Code</em>). Added these tags/attributes to the Source Editing Plugin\'s <a target="_blank" href="/admin/help/ckeditor5#source-editing">Manually editable HTML tags</a> setting: <cite> <dl> <dt> <dd> <span> <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>. Additional details are available in your logs.', + 'To maintain the capabilities of this text format, <a target="_blank" href="/admin/help/ckeditor5#migration-settings">the CKEditor 5 migration</a> did the following: Enabled these plugins: (<em class="placeholder">Link, Block quote, Code, List, Image, Image Upload, Image align, Image caption</em>). Added these tags/attributes to the Source Editing Plugin\'s <a target="_blank" href="/admin/help/ckeditor5#source-editing">Manually editable HTML tags</a> setting: <cite> <dl> <dt> <dd> <span> <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>. Additional details are available in your logs.', + ], + 'warning' => [ + 'Updating to CKEditor 5 added support for some previously unsupported tags/attributes. A plugin introduced support for the following: This attribute: <em class="placeholder"> reversed (for <ol>)</em>; Additional details are available in your logs.', ], ], ]; - yield "basic_html with media_embed added with data-view-mode allowed but no view modes configured (3 upgrade messages, 1 violation)" => [ + yield "basic_html with media_embed added with data-view-mode allowed and no view modes configured, but the drupalMedia toolbar item is not added automatically (3 upgrade messages, 1 violation)" => [ 'format_id' => 'basic_html_with_media_embed_view_mode_enabled_no_view_modes_configured', 'filters_to_drop' => $basic_html_test_case['filters_to_drop'], 'expected_ckeditor5_settings' => [ 'toolbar' => [ - 'items' => array_merge( - array_slice($basic_html_test_case['expected_ckeditor5_settings']['toolbar']['items'], 0, 10), - ['drupalMedia'], - array_slice($basic_html_test_case['expected_ckeditor5_settings']['toolbar']['items'], 10), - ), + 'items' => $basic_html_test_case['expected_ckeditor5_settings']['toolbar']['items'], + ], + 'plugins' => [ + 'ckeditor5_heading' => $basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_heading'], + 'ckeditor5_imageResize' => $basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_imageResize'], + 'ckeditor5_list' => $basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_list'], + 'ckeditor5_sourceEditing' => [ + 'allowed_tags' => array_merge( + $basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_sourceEditing']['allowed_tags'], + ['<drupal-media data-view-mode>'], + ), + ], + 'media_media' => ['allow_view_mode_override' => FALSE], ], - 'plugins' => array_merge($basic_html_test_case['expected_ckeditor5_settings']['plugins'], ['media_media' => ['allow_view_mode_override' => TRUE]]), ], 'expected_superset' => $basic_html_test_case['expected_superset'], 'expected_fundamental_compatibility_violations' => $basic_html_test_case['expected_fundamental_compatibility_violations'], 'expected_db_logs' => [ 'status' => [ - 'The CKEditor 5 migration enabled the following plugins to support tags that are allowed by the <em class="placeholder">(with Media Embed support, view mode enabled but no view modes configured)</em> text format: <em class="placeholder">Code (for tags: <code>)</em>. The text format must be saved to make these changes active.', + 'The CKEditor 5 migration enabled the following plugins to support tags that are allowed by the <em class="placeholder">(with Media Embed support, view mode enabled but no view modes configured)</em> text format: <em class="placeholder">Link (for tags: <a>) Block quote (for tags: <blockquote>) Code (for tags: <code>) List (for tags: <ul><ol><li>) Image (for tags: <img>)</em>. The text format must be saved to make these changes active.', 'The following tags were permitted by the <em class="placeholder">(with Media Embed support, view mode enabled but no view modes configured)</em> text format\'s filter configuration, but no plugin was available that supports them. To ensure the tags remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <cite> <dl> <dt> <dd> <span>. The text format must be saved to make these changes active.', - 'As part of migrating to CKEditor 5, it was found that the <em class="placeholder">(with Media Embed support, view mode enabled but no view modes configured)</em> text format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>. The text format must be saved to make these changes active.', + 'As part of migrating to CKEditor 5, it was found that the <em class="placeholder">(with Media Embed support, view mode enabled but no view modes configured)</em> text format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <drupal-media data-view-mode>. The text format must be saved to make these changes active.', ], ], 'expected_messages' => array_merge_recursive($basic_html_test_case['expected_messages'], [ 'status' => [ - 'To maintain the capabilities of this text format, <a target="_blank" href="/admin/help/ckeditor5#migration-settings">the CKEditor 5 migration</a> did the following: Enabled these plugins: (<em class="placeholder">Code</em>). Added these tags/attributes to the Source Editing Plugin\'s <a target="_blank" href="/admin/help/ckeditor5#source-editing">Manually editable HTML tags</a> setting: <cite> <dl> <dt> <dd> <span> <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>. Additional details are available in your logs.', + 'To maintain the capabilities of this text format, <a target="_blank" href="/admin/help/ckeditor5#migration-settings">the CKEditor 5 migration</a> did the following: Enabled these plugins: (<em class="placeholder">Link, Block quote, Code, List, Image, Image Upload, Image align, Image caption</em>). Added these tags/attributes to the Source Editing Plugin\'s <a target="_blank" href="/admin/help/ckeditor5#source-editing">Manually editable HTML tags</a> setting: <cite> <dl> <dt> <dd> <span> <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <drupal-media data-view-mode>. Additional details are available in your logs.', + ], + 'warning' => [ + 'Updating to CKEditor 5 added support for some previously unsupported tags/attributes. A plugin introduced support for the following: This attribute: <em class="placeholder"> reversed (for <ol>)</em>; Additional details are available in your logs.', ], ]), 'expected_post_filter_drop_fundamental_compatibility_violations' => [], 'expected_post_update_text_editor_violations' => [ - '' => 'The CKEditor 5 "<em class="placeholder">Media</em>" plugin\'s "<em class="placeholder">Allow the user to override the default view mode</em>" setting should be in sync with the "<em class="placeholder">Embed media</em>" filter\'s "<em class="placeholder">View modes selectable in the "Edit media" dialog</em>" setting: when checked, two or more view modes must be allowed by the filter.', + 'settings.plugins.ckeditor5_sourceEditing.allowed_tags.14' => 'The following attribute(s) can optionally be supported by enabled plugins and should not be added to the Source Editing "Manually editable HTML tags" field: <em class="placeholder">Media (<drupal-media data-view-mode>)</em>.', ], ]; - yield "basic_html with media_embed added with data-view-mode allowed and 2 view modes configured (3 upgrade messages)" => [ + yield "basic_html with media_embed added with data-view-mode allowed and 2 view modes configured, but the drupalMedia toolbar item is not added automatically (3 upgrade messages, 1 violation)" => [ 'format_id' => 'basic_html_with_media_embed_view_mode_enabled_two_view_modes_configured', 'filters_to_drop' => $basic_html_test_case['filters_to_drop'], 'expected_ckeditor5_settings' => [ 'toolbar' => [ - 'items' => array_merge( - array_slice($basic_html_test_case['expected_ckeditor5_settings']['toolbar']['items'], 0, 10), - ['drupalMedia'], - array_slice($basic_html_test_case['expected_ckeditor5_settings']['toolbar']['items'], 10), - ), + 'items' => $basic_html_test_case['expected_ckeditor5_settings']['toolbar']['items'], + ], + 'plugins' => [ + 'ckeditor5_heading' => $basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_heading'], + 'ckeditor5_imageResize' => $basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_imageResize'], + 'ckeditor5_list' => $basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_list'], + 'ckeditor5_sourceEditing' => [ + 'allowed_tags' => array_merge( + $basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_sourceEditing']['allowed_tags'], + ['<drupal-media data-view-mode>'], + ), + ], + 'media_media' => ['allow_view_mode_override' => FALSE], ], - 'plugins' => array_merge($basic_html_test_case['expected_ckeditor5_settings']['plugins'], ['media_media' => ['allow_view_mode_override' => TRUE]]), ], 'expected_superset' => $basic_html_test_case['expected_superset'], 'expected_fundamental_compatibility_violations' => $basic_html_test_case['expected_fundamental_compatibility_violations'], 'expected_db_logs' => [ 'status' => [ - 'The CKEditor 5 migration enabled the following plugins to support tags that are allowed by the <em class="placeholder">(with Media Embed support, view mode enabled and two view modes configured )</em> text format: <em class="placeholder">Code (for tags: <code>)</em>. The text format must be saved to make these changes active.', + 'The CKEditor 5 migration enabled the following plugins to support tags that are allowed by the <em class="placeholder">(with Media Embed support, view mode enabled and two view modes configured )</em> text format: <em class="placeholder">Link (for tags: <a>) Block quote (for tags: <blockquote>) Code (for tags: <code>) List (for tags: <ul><ol><li>) Image (for tags: <img>)</em>. The text format must be saved to make these changes active.', 'The following tags were permitted by the <em class="placeholder">(with Media Embed support, view mode enabled and two view modes configured )</em> text format\'s filter configuration, but no plugin was available that supports them. To ensure the tags remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <cite> <dl> <dt> <dd> <span>. The text format must be saved to make these changes active.', - 'As part of migrating to CKEditor 5, it was found that the <em class="placeholder">(with Media Embed support, view mode enabled and two view modes configured )</em> text format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>. The text format must be saved to make these changes active.', + 'As part of migrating to CKEditor 5, it was found that the <em class="placeholder">(with Media Embed support, view mode enabled and two view modes configured )</em> text format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <drupal-media data-view-mode>. The text format must be saved to make these changes active.', ], ], 'expected_messages' => array_merge_recursive($basic_html_test_case['expected_messages'], [ 'status' => [ - 'To maintain the capabilities of this text format, <a target="_blank" href="/admin/help/ckeditor5#migration-settings">the CKEditor 5 migration</a> did the following: Enabled these plugins: (<em class="placeholder">Code</em>). Added these tags/attributes to the Source Editing Plugin\'s <a target="_blank" href="/admin/help/ckeditor5#source-editing">Manually editable HTML tags</a> setting: <cite> <dl> <dt> <dd> <span> <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>. Additional details are available in your logs.', + 'To maintain the capabilities of this text format, <a target="_blank" href="/admin/help/ckeditor5#migration-settings">the CKEditor 5 migration</a> did the following: Enabled these plugins: (<em class="placeholder">Link, Block quote, Code, List, Image, Image Upload, Image align, Image caption</em>). Added these tags/attributes to the Source Editing Plugin\'s <a target="_blank" href="/admin/help/ckeditor5#source-editing">Manually editable HTML tags</a> setting: <cite> <dl> <dt> <dd> <span> <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <drupal-media data-view-mode>. Additional details are available in your logs.', + ], + 'warning' => [ + 'Updating to CKEditor 5 added support for some previously unsupported tags/attributes. A plugin introduced support for the following: This attribute: <em class="placeholder"> reversed (for <ol>)</em>; Additional details are available in your logs.', ], ]), 'expected_post_filter_drop_fundamental_compatibility_violations' => [], - 'expected_post_update_text_editor_violations' => [], + 'expected_post_update_text_editor_violations' => [ + 'settings.plugins.ckeditor5_sourceEditing.allowed_tags.14' => 'The following attribute(s) can optionally be supported by enabled plugins and should not be added to the Source Editing "Manually editable HTML tags" field: <em class="placeholder">Media (<drupal-media data-view-mode>)</em>.', + ], ]; yield "basic_html_with_any_data_attr can be switched to CKEditor 5 without problems (3 upgrade messages)" => [ @@ -1170,8 +1121,9 @@ public static function provider() { 'ckeditor5_list' => $basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_list'], 'ckeditor5_sourceEditing' => [ 'allowed_tags' => array_merge( - $basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_sourceEditing']['allowed_tags'], + array_slice($basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_sourceEditing']['allowed_tags'], 0, 9), ['<img data-*>'], + array_slice($basic_html_test_case['expected_ckeditor5_settings']['plugins']['ckeditor5_sourceEditing']['allowed_tags'], 9), ), ], ] + $basic_html_test_case['expected_ckeditor5_settings']['plugins'], @@ -1180,14 +1132,17 @@ public static function provider() { 'expected_fundamental_compatibility_violations' => $basic_html_test_case['expected_fundamental_compatibility_violations'], 'expected_db_logs' => [ 'status' => [ - 'The CKEditor 5 migration enabled the following plugins to support tags that are allowed by the <em class="placeholder">Basic HTML (with any data-* attribute on images)</em> text format: <em class="placeholder">Code (for tags: <code>)</em>. The text format must be saved to make these changes active.', + 'The CKEditor 5 migration enabled the following plugins to support tags that are allowed by the <em class="placeholder">Basic HTML (with any data-* attribute on images)</em> text format: <em class="placeholder">Link (for tags: <a>) Block quote (for tags: <blockquote>) Code (for tags: <code>) List (for tags: <ul><ol><li>) Image (for tags: <img>)</em>. The text format must be saved to make these changes active.', 'The following tags were permitted by the <em class="placeholder">Basic HTML (with any data-* attribute on images)</em> text format\'s filter configuration, but no plugin was available that supports them. To ensure the tags remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <cite> <dl> <dt> <dd> <span>. The text format must be saved to make these changes active.', - 'As part of migrating to CKEditor 5, it was found that the <em class="placeholder">Basic HTML (with any data-* attribute on images)</em> text format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <img data-*>. The text format must be saved to make these changes active.', + 'As part of migrating to CKEditor 5, it was found that the <em class="placeholder">Basic HTML (with any data-* attribute on images)</em> text format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <a hreflang> <blockquote cite> <ul type> <ol type> <img data-*> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>. The text format must be saved to make these changes active.', ], ], 'expected_messages' => [ 'status' => [ - 'To maintain the capabilities of this text format, <a target="_blank" href="/admin/help/ckeditor5#migration-settings">the CKEditor 5 migration</a> did the following: Enabled these plugins: (<em class="placeholder">Code</em>). Added these tags/attributes to the Source Editing Plugin\'s <a target="_blank" href="/admin/help/ckeditor5#source-editing">Manually editable HTML tags</a> setting: <cite> <dl> <dt> <dd> <span> <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <img data-*>. Additional details are available in your logs.', + 'To maintain the capabilities of this text format, <a target="_blank" href="/admin/help/ckeditor5#migration-settings">the CKEditor 5 migration</a> did the following: Enabled these plugins: (<em class="placeholder">Link, Block quote, Code, List, Image, Image Upload</em>). Added these tags/attributes to the Source Editing Plugin\'s <a target="_blank" href="/admin/help/ckeditor5#source-editing">Manually editable HTML tags</a> setting: <cite> <dl> <dt> <dd> <span> <a hreflang> <blockquote cite> <ul type> <ol type> <img data-*> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>. Additional details are available in your logs.', + ], + 'warning' => [ + 'Updating to CKEditor 5 added support for some previously unsupported tags/attributes. A plugin introduced support for the following: This attribute: <em class="placeholder"> reversed (for <ol>)</em>; Additional details are available in your logs.', ], ], ]; @@ -1198,12 +1153,12 @@ public static function provider() { 'expected_ckeditor5_settings' => [ 'toolbar' => [ 'items' => [ - // Items originating from CKEditor5::getDefaultSettings(). + // Default toolbar items. 'heading', 'bold', 'italic', - // Items added based on "allowed tags" config. '|', + // Items added based on "allowed tags" config. // Because '<a>' is in allowed_html. 'link', // Because '<blockquote cite>' is in allowed_html. @@ -1215,6 +1170,7 @@ public static function provider() { // Because '<ol>' is in allowed_html. 'numberedList', // Because additional tags need to be allowed to achieve a superset. + '|', 'sourceEditing', ], ], @@ -1230,7 +1186,7 @@ public static function provider() { ], 'ckeditor5_list' => [ 'properties' => [ - 'reversed' => FALSE, + 'reversed' => TRUE, 'startIndex' => TRUE, ], 'multiBlock' => TRUE, @@ -1254,7 +1210,7 @@ public static function provider() { ], ], ], - 'expected_superset' => '<br> <p>', + 'expected_superset' => '<br> <p> <ol reversed>', 'expected_fundamental_compatibility_violations' => [ '' => 'CKEditor 5 needs at least the <p> and <br> tags to be allowed to be able to function. They are not allowed by the "<em class="placeholder">Limit allowed HTML tags and correct faulty HTML</em>" (<em class="placeholder">filter_html</em>) filter.', ], @@ -1273,61 +1229,28 @@ public static function provider() { 'To maintain the capabilities of this text format, <a target="_blank" href="/admin/help/ckeditor5#migration-settings">the CKEditor 5 migration</a> did the following: Enabled these plugins: (<em class="placeholder">Link, Block quote, Code, List</em>). Added these tags/attributes to the Source Editing Plugin\'s <a target="_blank" href="/admin/help/ckeditor5#source-editing">Manually editable HTML tags</a> setting: <cite> <dl> <dt> <dd> <a hreflang> <blockquote cite> <ul type> <ol type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>. Additional details are available in your logs.', ], 'warning' => [ - 'Updating to CKEditor 5 added support for some previously unsupported tags/attributes. A plugin introduced support for the following: The <br>, <p> tags were added because they are <a target="_blank" href="/admin/help/ckeditor5#required-tags">required by CKEditor 5</a>. The tags <em class="placeholder"><h2>, <h3>, <h4>, <h5>, <h6>, <*>, <cite>, <dl>, <dt>, <dd>, <a>, <blockquote>, <ul>, <ol>, <strong>, <em>, <code>, <li></em>; These attributes: <em class="placeholder"> id (for <h2>, <h3>, <h4>, <h5>, <h6>), dir (for <*>), lang (for <*>), hreflang (for <a>), href (for <a>), cite (for <blockquote>), type (for <ul>, <ol>), start (for <ol>)</em>; Additional details are available in your logs.', + 'Updating to CKEditor 5 added support for some previously unsupported tags/attributes. A plugin introduced support for the following: The <br>, <p> tags were added because they are <a target="_blank" href="/admin/help/ckeditor5#required-tags">required by CKEditor 5</a>. The tags <em class="placeholder"><h2>, <h3>, <h4>, <h5>, <h6>, <*>, <cite>, <dl>, <dt>, <dd>, <a>, <blockquote>, <ul>, <ol>, <strong>, <em>, <code>, <li></em>; These attributes: <em class="placeholder"> id (for <h2>, <h3>, <h4>, <h5>, <h6>), dir (for <*>), lang (for <*>), hreflang (for <a>), href (for <a>), cite (for <blockquote>), type (for <ul>, <ol>), reversed (for <ol>), start (for <ol>)</em>; Additional details are available in your logs.', ], ], 'expected_post_filter_drop_fundamental_compatibility_violations' => [], ]; - yield "full_html can be switched to CKEditor 5 (no upgrade messages)" => [ + yield "full_html can be switched to CKEditor 5 (no upgrade messages), uses only default toolbar items because impossible to know toolbar items are desired" => [ 'format_id' => 'full_html', 'filters_to_drop' => [], 'expected_ckeditor5_settings' => [ 'toolbar' => [ 'items' => [ + // Default toolbar items. + 'heading', 'bold', 'italic', - 'strikethrough', - 'superscript', - 'subscript', - 'removeFormat', - '|', - 'link', - '|', - 'bulletedList', - 'numberedList', + // Because there are no HTML restrictions. '|', - 'blockQuote', - 'drupalInsertImage', - 'insertTable', - 'horizontalLine', - '|', - 'heading', - 'codeBlock', - '|', - 'showBlocks', 'sourceEditing', ], ], 'plugins' => [ - 'ckeditor5_codeBlock' => [ - 'languages' => [ - ['label' => 'Plain text', 'language' => 'plaintext'], - ['label' => 'C', 'language' => 'c'], - ['label' => 'C#', 'language' => 'cs'], - ['label' => 'C++', 'language' => 'cpp'], - ['label' => 'CSS', 'language' => 'css'], - ['label' => 'Diff', 'language' => 'diff'], - ['label' => 'HTML', 'language' => 'html'], - ['label' => 'Java', 'language' => 'java'], - ['label' => 'JavaScript', 'language' => 'javascript'], - ['label' => 'PHP', 'language' => 'php'], - ['label' => 'Python', 'language' => 'python'], - ['label' => 'Ruby', 'language' => 'ruby'], - ['label' => 'TypeScript', 'language' => 'typescript'], - ['label' => 'XML', 'language' => 'xml'], - ], - ], 'ckeditor5_heading' => [ 'enabled_headings' => [ 'heading2', @@ -1337,16 +1260,6 @@ public static function provider() { 'heading6', ], ], - 'ckeditor5_imageResize' => [ - 'allow_resize' => TRUE, - ], - 'ckeditor5_list' => [ - 'properties' => [ - 'reversed' => TRUE, - 'startIndex' => TRUE, - ], - 'multiBlock' => TRUE, - ], 'ckeditor5_sourceEditing' => [ 'allowed_tags' => [], ], @@ -1375,6 +1288,8 @@ public static function provider() { 'code', 'bulletedList', 'numberedList', + // Because additional tags need to be allowed to achieve a superset. + '|', 'sourceEditing', ], ], @@ -1390,7 +1305,7 @@ public static function provider() { ], 'ckeditor5_list' => [ 'properties' => [ - 'reversed' => FALSE, + 'reversed' => TRUE, 'startIndex' => TRUE, ], 'multiBlock' => TRUE, @@ -1414,7 +1329,7 @@ public static function provider() { ], ], ], - 'expected_superset' => '<br> <p>', + 'expected_superset' => '<br> <p> <ol reversed>', 'expected_fundamental_compatibility_violations' => [ '' => 'CKEditor 5 needs at least the <p> and <br> tags to be allowed to be able to function. They are not allowed by the "<em class="placeholder">Limit allowed HTML tags and correct faulty HTML</em>" (<em class="placeholder">filter_html</em>) filter.', ], @@ -1433,56 +1348,7 @@ public static function provider() { 'To maintain the capabilities of this text format, <a target="_blank" href="/admin/help/ckeditor5#migration-settings">the CKEditor 5 migration</a> did the following: Enabled these plugins: (<em class="placeholder">Link, Block quote, Code, List</em>). Added these tags/attributes to the Source Editing Plugin\'s <a target="_blank" href="/admin/help/ckeditor5#source-editing">Manually editable HTML tags</a> setting: <cite> <dl> <dt> <dd> <a hreflang> <blockquote cite> <ul type> <ol type="1 A I"> <h2 id="jump-*"> <h3 id> <h4 id> <h5 id> <h6 id>. Additional details are available in your logs.', ], 'warning' => [ - 'Updating to CKEditor 5 added support for some previously unsupported tags/attributes. A plugin introduced support for the following: The <br>, <p> tags were added because they are <a target="_blank" href="/admin/help/ckeditor5#required-tags">required by CKEditor 5</a>. The tags <em class="placeholder"><h2>, <h3>, <h4>, <h5>, <h6>, <*>, <cite>, <dl>, <dt>, <dd>, <a>, <blockquote>, <ul>, <ol>, <strong>, <em>, <code>, <li></em>; These attributes: <em class="placeholder"> id (for <h2>, <h3>, <h4>, <h5>, <h6>), dir (for <*>), lang (for <*>), hreflang (for <a>), href (for <a>), cite (for <blockquote>), type (for <ul>, <ol>), start (for <ol>)</em>; Additional details are available in your logs.', - ], - ], - ]; - - yield "cke4_plugins_with_settings can be switched to CKEditor 5 without problems, settings are upgraded too" => [ - 'format_id' => 'cke4_plugins_with_settings', - 'filters_to_drop' => [], - 'expected_ckeditor5_settings' => [ - 'toolbar' => [ - 'items' => [ - 'textPartLanguage', - 'style', - 'blockQuote', - ], - ], - 'plugins' => [ - 'ckeditor5_language' => [ - 'language_list' => 'all', - ], - 'ckeditor5_style' => [ - 'styles' => [ - [ - 'label' => 'Callout', - 'element' => '<p class="callout">', - ], - [ - 'label' => 'Interesting & highlighted quote', - 'element' => '<blockquote class="interesting highlighted">', - ], - [ - 'label' => 'Famous', - 'element' => '<blockquote class="famous">', - ], - ], - ], - ], - ], - 'expected_superset' => '', - 'expected_fundamental_compatibility_violations' => [], - 'expected_db_logs' => [ - 'warning' => [ - 'The CKEditor 4 button <em class="placeholder">Llama</em> does not have a known upgrade path. If it allowed editing markup, then you can do so now through the Source Editing functionality.', - 'The <em class="placeholder">llama_contextual_and_button</em> plugin settings do not have a known upgrade path.', - ], - ], - 'expected_messages' => [ - 'warning' => [ - 'The CKEditor 4 button <em class="placeholder">Llama</em> does not have a known upgrade path. If it allowed editing markup, then you can do so now through the Source Editing functionality.', - 'The <em class="placeholder">llama_contextual_and_button</em> plugin settings do not have a known upgrade path.', + 'Updating to CKEditor 5 added support for some previously unsupported tags/attributes. A plugin introduced support for the following: The <br>, <p> tags were added because they are <a target="_blank" href="/admin/help/ckeditor5#required-tags">required by CKEditor 5</a>. The tags <em class="placeholder"><h2>, <h3>, <h4>, <h5>, <h6>, <*>, <cite>, <dl>, <dt>, <dd>, <a>, <blockquote>, <ul>, <ol>, <strong>, <em>, <code>, <li></em>; These attributes: <em class="placeholder"> id (for <h2>, <h3>, <h4>, <h5>, <h6>), dir (for <*>), lang (for <*>), hreflang (for <a>), href (for <a>), cite (for <blockquote>), type (for <ul>, <ol>), reversed (for <ol>), start (for <ol>)</em>; Additional details are available in your logs.', ], ], ]; @@ -1493,107 +1359,92 @@ public static function provider() { 'expected_ckeditor5_settings' => [ 'toolbar' => [ 'items' => [ - 'style', + // Default toolbar items. + 'heading', + 'bold', + 'italic', + // Because additional tags need to be allowed to achieve a superset. + '|', 'sourceEditing', ], ], 'plugins' => [ - 'ckeditor5_sourceEditing' => [ - 'allowed_tags' => [ - '<span>', + 'ckeditor5_heading' => [ + 'enabled_headings' => [ + 'heading2', + 'heading3', + 'heading4', + 'heading5', + 'heading6', ], ], - 'ckeditor5_style' => [ - 'styles' => [ - [ - 'label' => 'Llama span', - 'element' => '<span class="llama">', - ], + 'ckeditor5_sourceEditing' => [ + 'allowed_tags' => [ + '<span class="llama">', ], ], ], ], - 'expected_superset' => '', + 'expected_superset' => '<h2> <h3> <h4> <h5> <h6> <strong> <em>', 'expected_fundamental_compatibility_violations' => [], 'expected_db_logs' => [ 'status' => [ - "The following tags were permitted by the <em class=\"placeholder\">A CKEditor 4 configured to have span styles</em> text format's filter configuration, but no plugin was available that supports them. To ensure the tags remain supported by this text format, the following were added to the Source Editing plugin's <em>Manually editable HTML tags</em>: <span>. The text format must be saved to make these changes active.", + 'As part of migrating to CKEditor 5, it was found that the <em class="placeholder">A CKEditor 4 configured to have span styles</em> text format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: <span class="llama">. The text format must be saved to make these changes active.', ], ], 'expected_messages' => [ 'status' => [ - 'To maintain the capabilities of this text format, <a target="_blank" href="/admin/help/ckeditor5#migration-settings">the CKEditor 5 migration</a> did the following: Added these tags/attributes to the Source Editing Plugin\'s <a target="_blank" href="/admin/help/ckeditor5#source-editing">Manually editable HTML tags</a> setting: <span>. Additional details are available in your logs.', + 'To maintain the capabilities of this text format, <a target="_blank" href="/admin/help/ckeditor5#migration-settings">the CKEditor 5 migration</a> did the following: Added these tags/attributes to the Source Editing Plugin\'s <a target="_blank" href="/admin/help/ckeditor5#source-editing">Manually editable HTML tags</a> setting: <span class="llama">. Additional details are available in your logs.', + ], + 'warning' => [ + 'Updating to CKEditor 5 added support for some previously unsupported tags/attributes. A plugin introduced support for the following: The tags <em class="placeholder"><h2>, <h3>, <h4>, <h5>, <h6>, <strong>, <em></em>; Additional details are available in your logs.', ], ], ]; - yield "cke4_contrib_plugins_now_in_core can be switched to CKEditor 5 without problems" => [ - 'format_id' => 'cke4_contrib_plugins_now_in_core', + yield "minimal_ckeditor_wrong_allowed_html does not have sufficient allowed HTML => necessary allowed HTML added (1 upgrade message)" => [ + 'format_id' => 'minimal_ckeditor_wrong_allowed_html', 'filters_to_drop' => [], 'expected_ckeditor5_settings' => [ 'toolbar' => [ 'items' => [ - 'code', + // Default toolbar items. + 'heading', + 'bold', + 'italic', '|', - 'codeBlock', + 'link', ], ], 'plugins' => [ - 'ckeditor5_codeBlock' => [ - 'languages' => [ - ['label' => 'cs', 'language' => 'cs'], - ['label' => 'cpp', 'language' => 'cpp'], - ['label' => 'coffeescript', 'language' => 'coffeescript'], - ['label' => 'css', 'language' => 'css'], - ['label' => 'diff', 'language' => 'diff'], - ['label' => 'html', 'language' => 'html'], - ['label' => 'http', 'language' => 'http'], - ['label' => 'ini', 'language' => 'ini'], - ['label' => 'java', 'language' => 'java'], - ['label' => 'javascript', 'language' => 'javascript'], - ['label' => 'json', 'language' => 'json'], - ['label' => 'makefile', 'language' => 'makefile'], - ['label' => 'markdown', 'language' => 'markdown'], - ['label' => 'nginx', 'language' => 'nginx'], - ['label' => 'objectivec', 'language' => 'objectivec'], - ['label' => 'perl', 'language' => 'perl'], - ['label' => 'php', 'language' => 'php'], - ['label' => 'python', 'language' => 'python'], - ['label' => 'ruby', 'language' => 'ruby'], - ['label' => 'sql', 'language' => 'sql'], - ['label' => 'vbscript', 'language' => 'vbscript'], - ['label' => 'xhtml', 'language' => 'xhtml'], - ['label' => 'xml', 'language' => 'xml'], + 'ckeditor5_heading' => [ + 'enabled_headings' => [ + 'heading2', + 'heading3', + 'heading4', + 'heading5', + 'heading6', ], ], ], ], - 'expected_superset' => '', + 'expected_superset' => '<h2> <h3> <h4> <h5> <h6> <strong> <em> <a href>', 'expected_fundamental_compatibility_violations' => [], - 'expected_db_logs' => [], - 'expected_messages' => [], - ]; - - yield "minimal_ckeditor_wrong_allowed_html does not have sufficient allowed HTML => necessary allowed HTML added (1 upgrade message)" => [ - 'format_id' => 'minimal_ckeditor_wrong_allowed_html', - 'filters_to_drop' => [], - 'expected_ckeditor5_settings' => [ - 'toolbar' => [ - 'items' => [ - 'link', - ], + 'expected_db_logs' => [ + 'status' => [ + 'The CKEditor 5 migration enabled the following plugins to support tags that are allowed by the <em class="placeholder">Most basic HTML, but with allowed_html misconfigured</em> text format: <em class="placeholder">Link (for tags: <a>)</em>. The text format must be saved to make these changes active.', ], - 'plugins' => [], ], - 'expected_superset' => '<a href>', - 'expected_fundamental_compatibility_violations' => [], - 'expected_db_logs' => [], 'expected_messages' => [ + 'status' => [ + 'To maintain the capabilities of this text format, <a target="_blank" href="/admin/help/ckeditor5#migration-settings">the CKEditor 5 migration</a> did the following: Enabled these plugins: (<em class="placeholder">Link</em>). . Additional details are available in your logs.', + ], 'warning' => [ - 0 => 'Updating to CKEditor 5 added support for some previously unsupported tags/attributes. A plugin introduced support for the following: This attribute: <em class="placeholder"> href (for <a>)</em>; Additional details are available in your logs.', + 'Updating to CKEditor 5 added support for some previously unsupported tags/attributes. A plugin introduced support for the following: The tags <em class="placeholder"><h2>, <h3>, <h4>, <h5>, <h6>, <strong>, <em></em>; This attribute: <em class="placeholder"> href (for <a>)</em>; Additional details are available in your logs.', ], ], ]; + } } diff --git a/core/modules/ckeditor5/tests/src/Unit/SmartDefaultSettingsTest.php b/core/modules/ckeditor5/tests/src/Unit/SmartDefaultSettingsTest.php index ebeb5a12147ce2e0a093f57c7c6f9e2b09ae4109..c694c2870b45be15f885dda66f3dccfddb55485e 100644 --- a/core/modules/ckeditor5/tests/src/Unit/SmartDefaultSettingsTest.php +++ b/core/modules/ckeditor5/tests/src/Unit/SmartDefaultSettingsTest.php @@ -7,10 +7,15 @@ use Drupal\ckeditor5\Annotation\CKEditor5Plugin; use Drupal\ckeditor5\HTMLRestrictions; use Drupal\ckeditor5\Plugin\CKEditor5PluginDefinition; +use Drupal\ckeditor5\Plugin\CKEditor5PluginManagerInterface; use Drupal\ckeditor5\SmartDefaultSettings; use Drupal\Component\Utility\NestedArray; +use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\Core\Session\AccountInterface; +use Drupal\editor\EditorInterface; use Drupal\Tests\ckeditor5\Traits\PrivateMethodUnitTestTrait; use Drupal\Tests\UnitTestCase; +use Psr\Log\LoggerInterface; /** * @coversDefaultClass \Drupal\ckeditor5\SmartDefaultSettings @@ -82,7 +87,14 @@ public static function providerSurplusScore(): \Generator { */ public function testCandidates(HTMLRestrictions $provided, HTMLRestrictions $still_needed, array $disabled_plugin_definitions, array $expected_candidates, array $expected_selection = []): void { $get_candidates = self::getMethod(SmartDefaultSettings::class, 'getCandidates'); - $this->assertSame($expected_candidates, $get_candidates->invoke(NULL, $provided, $still_needed, $disabled_plugin_definitions)); + $smart_default_settings = new SmartDefaultSettings( + $this->prophesize(CKEditor5PluginManagerInterface::class)->reveal(), + $this->prophesize(LoggerInterface::class)->reveal(), + $this->prophesize(ModuleHandlerInterface::class)->reveal(), + $this->prophesize(AccountInterface::class)->reveal(), + ); + $editor = $this->prophesize(EditorInterface::class); + $this->assertSame($expected_candidates, $get_candidates->invoke($smart_default_settings, $provided, $still_needed, $disabled_plugin_definitions, $editor->reveal())); $select_candidate = self::getMethod(SmartDefaultSettings::class, 'selectCandidate'); $this->assertSame($expected_selection, $select_candidate->invoke(NULL, $expected_candidates, $still_needed, array_keys($provided->getAllowedElements()))); }