Skip to content
Snippets Groups Projects
Verified Commit c94dc2dc authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3274278 by Wim Leers, jcnventura, yogeshmpawar, andregp, bnjmnm:...

Issue #3274278 by Wim Leers, jcnventura, yogeshmpawar, andregp, bnjmnm: Migrate "codetag" contrib CKEditor 4 plugin to built-in equivalent in core's CKEditor 5

(cherry picked from commit 46903e6c)
parent d4bf3002
No related branches found
No related tags found
5 merge requests!2496Issue #3222757 by lauriii, Wim Leers, nod_, rachel_norfolk, itmaybejj,...,!2366Issue #3285105 by Daniel Arend,!2304Issue #3258987: Class "Drupal\Core\Utility\Error" not found in _drupal_error_handler_real() due to bug in PHP 8.1.0-8.1.5,!2148Issue #3270899: Remove Color module from core,!1387Draft: Resolve #2511878 "Support enclosure field"
<?php
declare(strict_types=1);
namespace Drupal\ckeditor5\Plugin\CKEditor4To5Upgrade;
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"
* },
* cke4_plugin_settings = {
* },
* 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'];
default:
throw new \OutOfBoundsException();
}
}
/**
* {@inheritdoc}
*/
public function mapCKEditor4SettingsToCKEditor5Configuration(string $cke4_plugin_id, array $cke4_plugin_settings): ?array {
throw new \OutOfBoundsException();
}
/**
* {@inheritdoc}
*/
public function computeCKEditor5PluginSubsetConfiguration(string $cke5_plugin_id, FilterFormatInterface $text_format): ?array {
throw new \OutOfBoundsException();
}
}
......@@ -19,6 +19,19 @@
*/
class CKEditor4to5UpgradeCompletenessTest extends KernelTestBase {
/**
* The CKEditor 4 toolbar buttons that no longer require a contrib module.
*
* @var string[]
*
* @see \Drupal\ckeditor5\Plugin\CKEditor4To5Upgrade\Contrib
*/
const CONTRIB_BUTTONS_NOW_IN_CORE = [
// @see https://www.drupal.org/project/codetag
// @see ckeditor5_code's `basicStyles.Code` plugin
'Code',
];
/**
* The "CKEditor 4 plugin" plugin manager.
*
......@@ -89,6 +102,7 @@ protected function setUp(): void {
*/
public function testButtons(): void {
$cke4_buttons = array_keys(NestedArray::mergeDeepArray($this->cke4PluginManager->getButtons()));
$cke4_buttons = array_merge($cke4_buttons, self::CONTRIB_BUTTONS_NOW_IN_CORE);
foreach ($cke4_buttons as $button) {
$equivalent = $this->upgradePluginManager->mapCKEditor4ToolbarButtonToCKEditor5ToolbarItem($button, HTMLRestrictions::emptySet());
......
......@@ -261,6 +261,30 @@ 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',
],
],
],
],
],
'plugins' => [],
],
])->save();
}
/**
......@@ -924,6 +948,22 @@ public function provider() {
'expected_fundamental_compatibility_violations' => [],
'expected_messages' => [],
];
yield "cke4_contrib_plugins_now_in_core can be switched to CKEditor 5 without problems" => [
'format_id' => 'cke4_contrib_plugins_now_in_core',
'filters_to_drop' => [],
'expected_ckeditor5_settings' => [
'toolbar' => [
'items' => [
'code',
],
],
'plugins' => [],
],
'expected_superset' => '',
'expected_fundamental_compatibility_violations' => [],
'expected_messages' => [],
];
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment