Issue #3356929 by Wim Leers, kevinquillen: Provide an upgrade path from "codesnippet" contrib CKEditor 4 plugin to "CodeBlock" core CKEditor 5 plugin
parent
575c533130
commit
dd9c718324
|
@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Drupal\ckeditor5\Plugin\CKEditor4To5Upgrade;
|
namespace Drupal\ckeditor5\Plugin\CKEditor4To5Upgrade;
|
||||||
|
|
||||||
|
// cspell:ignore codesnippet
|
||||||
|
|
||||||
use Drupal\ckeditor5\HTMLRestrictions;
|
use Drupal\ckeditor5\HTMLRestrictions;
|
||||||
use Drupal\ckeditor5\Plugin\CKEditor4To5UpgradePluginInterface;
|
use Drupal\ckeditor5\Plugin\CKEditor4To5UpgradePluginInterface;
|
||||||
use Drupal\Core\Plugin\PluginBase;
|
use Drupal\Core\Plugin\PluginBase;
|
||||||
|
@ -15,9 +17,11 @@ use Drupal\filter\FilterFormatInterface;
|
||||||
* @CKEditor4To5Upgrade(
|
* @CKEditor4To5Upgrade(
|
||||||
* id = "contrib",
|
* id = "contrib",
|
||||||
* cke4_buttons = {
|
* cke4_buttons = {
|
||||||
* "Code"
|
* "Code",
|
||||||
|
* "CodeSnippet",
|
||||||
* },
|
* },
|
||||||
* cke4_plugin_settings = {
|
* cke4_plugin_settings = {
|
||||||
|
* "codesnippet",
|
||||||
* },
|
* },
|
||||||
* cke5_plugin_elements_subset_configuration = {
|
* cke5_plugin_elements_subset_configuration = {
|
||||||
* }
|
* }
|
||||||
|
@ -37,6 +41,10 @@ class Contrib extends PluginBase implements CKEditor4To5UpgradePluginInterface {
|
||||||
case 'Code':
|
case 'Code':
|
||||||
return ['code'];
|
return ['code'];
|
||||||
|
|
||||||
|
// @see https://www.drupal.org/project/codesnippet
|
||||||
|
case 'CodeSnippet':
|
||||||
|
return ['codeBlock'];
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new \OutOfBoundsException();
|
throw new \OutOfBoundsException();
|
||||||
}
|
}
|
||||||
|
@ -46,7 +54,25 @@ class Contrib extends PluginBase implements CKEditor4To5UpgradePluginInterface {
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function mapCKEditor4SettingsToCKEditor5Configuration(string $cke4_plugin_id, array $cke4_plugin_settings): ?array {
|
public function mapCKEditor4SettingsToCKEditor5Configuration(string $cke4_plugin_id, array $cke4_plugin_settings): ?array {
|
||||||
throw new \OutOfBoundsException();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,6 +4,8 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace Drupal\Tests\ckeditor5\Kernel;
|
namespace Drupal\Tests\ckeditor5\Kernel;
|
||||||
|
|
||||||
|
// cspell:ignore arta codesnippet
|
||||||
|
|
||||||
use Drupal\ckeditor5\HTMLRestrictions;
|
use Drupal\ckeditor5\HTMLRestrictions;
|
||||||
use Drupal\Component\Render\FormattableMarkup;
|
use Drupal\Component\Render\FormattableMarkup;
|
||||||
use Drupal\Component\Utility\NestedArray;
|
use Drupal\Component\Utility\NestedArray;
|
||||||
|
@ -423,9 +425,50 @@ class SmartDefaultSettingsTest extends KernelTestBase {
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
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,
|
||||||
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'plugins' => [],
|
|
||||||
],
|
],
|
||||||
])->setSyncing(TRUE)->save();
|
])->setSyncing(TRUE)->save();
|
||||||
}
|
}
|
||||||
|
@ -1452,9 +1495,39 @@ class SmartDefaultSettingsTest extends KernelTestBase {
|
||||||
'toolbar' => [
|
'toolbar' => [
|
||||||
'items' => [
|
'items' => [
|
||||||
'code',
|
'code',
|
||||||
|
'|',
|
||||||
|
'codeBlock',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'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'],
|
||||||
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'plugins' => [],
|
|
||||||
],
|
],
|
||||||
'expected_superset' => '',
|
'expected_superset' => '',
|
||||||
'expected_fundamental_compatibility_violations' => [],
|
'expected_fundamental_compatibility_violations' => [],
|
||||||
|
|
Loading…
Reference in New Issue