core/modules/ckeditor5/ckeditor5.post_update.php | 26 +++++++++++++++++++++- .../src/Plugin/CKEditor5Plugin/CodeBlock.php | 6 +---- .../CKEditor5UpdateCodeBlockConfigurationTest.php | 1 + 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/core/modules/ckeditor5/ckeditor5.post_update.php b/core/modules/ckeditor5/ckeditor5.post_update.php index 2ebd63f5c7..211478c868 100644 --- a/core/modules/ckeditor5/ckeditor5.post_update.php +++ b/core/modules/ckeditor5/ckeditor5.post_update.php @@ -102,6 +102,30 @@ function ckeditor5_post_update_code_block(&$sandbox = []) { } $settings = $editor->getSettings(); - return in_array('codeBlock', $settings['toolbar']['items'], TRUE); + if (in_array('codeBlock', $settings['toolbar']['items'], TRUE)) { + $settings = $editor->getSettings(); + // @see \Drupal\ckeditor5\Plugin\CKEditor5Plugin\CodeBlock::defaultConfiguration() + $settings['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'], + ], + ]; + $editor->setSettings($settings); + } + + return TRUE; }); } diff --git a/core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/CodeBlock.php b/core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/CodeBlock.php index e21b3a7ef6..5b745a35c1 100644 --- a/core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/CodeBlock.php +++ b/core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/CodeBlock.php @@ -71,12 +71,8 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form * The parsed equivalent: a list of arrays with each containing: * - label: the label after the pipe symbol, with whitespace trimmed * - language: the key for the language - * - * @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. */ - public static function parseLanguagesFromValue(string $form_value): array { + protected static function parseLanguagesFromValue(string $form_value): array { $unparseable_lines = []; $lines = explode("\n", $form_value); diff --git a/core/modules/ckeditor5/tests/src/Functional/Update/CKEditor5UpdateCodeBlockConfigurationTest.php b/core/modules/ckeditor5/tests/src/Functional/Update/CKEditor5UpdateCodeBlockConfigurationTest.php index 2d1540d90c..9bf6f33403 100644 --- a/core/modules/ckeditor5/tests/src/Functional/Update/CKEditor5UpdateCodeBlockConfigurationTest.php +++ b/core/modules/ckeditor5/tests/src/Functional/Update/CKEditor5UpdateCodeBlockConfigurationTest.php @@ -39,6 +39,7 @@ public function testUpdateCodeBlockConfigurationPostUpdate(): void { $editor = Editor::load('full_html'); $settings = $editor->getSettings(); $this->assertArrayHasKey('ckeditor5_codeBlock', $settings['plugins']); + // @see \Drupal\ckeditor5\Plugin\CKEditor5Plugin\CodeBlock::defaultConfiguration() $this->assertSame([ 'languages' => [ ['label' => 'Plain text', 'language' => 'plaintext'],