Loading core/modules/ckeditor5/ckeditor5.post_update.php +24 −0 Original line number Diff line number Diff line Loading @@ -65,3 +65,27 @@ function ckeditor5_post_update_image_toolbar_item(&$sandbox = []) { $config_entity_updater->update($sandbox, 'editor', $callback); } /** * Updates Text Editors using CKEditor 5 to sort plugin settings by plugin key. */ function ckeditor5_post_update_plugins_settings_export_order(&$sandbox = []) { $config_entity_updater = \Drupal::classResolver(ConfigEntityUpdater::class); $config_entity_updater->update($sandbox, 'editor', function (Editor $editor): bool { // Only try to update editors using CKEditor 5. if ($editor->getEditor() !== 'ckeditor5') { return FALSE; } $settings = $editor->getSettings(); // Nothing to do if there are fewer than two plugins with settings. if (count($settings['plugins']) < 2) { return FALSE; } ksort($settings['plugins']); $editor->setSettings($settings); return TRUE; }); } core/modules/ckeditor5/config/schema/ckeditor5.schema.yml +6 −0 Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ editor.settings.ckeditor5: mapping: items: type: sequence orderby: ~ label: 'Items' sequence: type: ckeditor5.toolbar_item Loading @@ -20,6 +21,7 @@ editor.settings.ckeditor5: plugins: type: sequence label: 'Plugins' orderby: key sequence: type: ckeditor5.plugin.[%key] constraints: Loading Loading @@ -51,6 +53,7 @@ ckeditor5.plugin.ckeditor5_heading: mapping: enabled_headings: type: sequence orderby: value label: 'Enabled Headings' constraints: NotBlank: Loading Loading @@ -80,6 +83,7 @@ ckeditor5.plugin.ckeditor5_sourceEditing: mapping: allowed_tags: type: sequence orderby: ~ label: 'Allowed Tags' sequence: type: ckeditor5.element Loading @@ -95,6 +99,7 @@ ckeditor5.plugin.ckeditor5_alignment: mapping: enabled_alignments: type: sequence orderby: value label: 'Enabled Alignments' constraints: NotBlank: Loading Loading @@ -143,6 +148,7 @@ ckeditor5.plugin.ckeditor5_style: mapping: styles: type: sequence orderby: ~ label: 'Styles' constraints: NotBlank: Loading core/modules/ckeditor5/tests/src/Functional/Update/CKEditor5UpdatePluginSettingsSortTest.php 0 → 100644 +69 −0 Original line number Diff line number Diff line <?php namespace Drupal\Tests\ckeditor5\Functional\Update; use Drupal\editor\Entity\Editor; use Drupal\FunctionalTests\Update\UpdatePathTestBase; /** * @covers ckeditor5_post_update_plugins_settings_export_order() * @group Update * @group ckeditor5 */ class CKEditor5UpdatePluginSettingsSortTest extends UpdatePathTestBase { /** * {@inheritdoc} */ protected $defaultTheme = 'stark'; /** * {@inheritdoc} */ protected function setDatabaseDumpFiles() { $this->databaseDumpFiles = [ __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-9.4.0.filled.standard.php.gz', ]; } /** * Ensure settings for CKEditor 5 plugins are sorted by plugin key. */ public function testUpdatePluginSettingsSortPostUpdate(): void { $editor = Editor::load('basic_html'); $settings = $editor->getSettings(); $plugin_settings_before = array_keys($settings['plugins']); $this->runUpdates(); $editor = Editor::load('basic_html'); $settings = $editor->getSettings(); $plugin_settings_after = array_keys($settings['plugins']); // Different sort before and after, but the same values. $this->assertNotSame($plugin_settings_before, $plugin_settings_after); sort($plugin_settings_before); $this->assertSame($plugin_settings_before, $plugin_settings_after); } /** * Ensure settings for CKEditor 5 plugins are sorted by plugin key. */ public function testUpdatePluginSettingsSortEntitySave(): void { $editor = Editor::load('basic_html'); $settings = $editor->getSettings(); $plugin_settings_before = array_keys($settings['plugins']); $editor->save(); $editor = Editor::load('basic_html'); $settings = $editor->getSettings(); $plugin_settings_after = array_keys($settings['plugins']); // Different sort before and after, but the same values. $this->assertNotSame($plugin_settings_before, $plugin_settings_after); sort($plugin_settings_before); $this->assertSame($plugin_settings_before, $plugin_settings_after); } } core/modules/ckeditor5/tests/src/Kernel/SmartDefaultSettingsTest.php +18 −14 Original line number Diff line number Diff line Loading @@ -497,6 +497,10 @@ public function test(string $format_id, array $filters_to_drop, array $expected_ $updated_text_editor->toArray() ); // Save this to ensure the config export order is applied. // @see \Drupal\Core\Config\StorableConfigBase::castValue() $updated_text_editor->save(); // We should now have the expected data in the Editor config entity. $this->assertSame('ckeditor5', $updated_text_editor->getEditor()); $this->assertSame($expected_ckeditor5_settings, $updated_text_editor->getSettings()); Loading Loading @@ -922,12 +926,12 @@ public function provider() { ), ], 'plugins' => array_merge( $basic_html_test_case['expected_ckeditor5_settings']['plugins'], [ 'ckeditor5_alignment' => [ 'enabled_alignments' => ['center', 'justify'], ], ], $basic_html_test_case['expected_ckeditor5_settings']['plugins'], ), ], 'expected_superset' => implode(' ', [ Loading Loading @@ -1124,6 +1128,10 @@ public function provider() { 'heading6', ], ], 'ckeditor5_list' => [ 'reversed' => FALSE, 'startIndex' => TRUE, ], 'ckeditor5_sourceEditing' => [ 'allowed_tags' => [ '<cite>', Loading @@ -1141,10 +1149,6 @@ public function provider() { '<h6 id>', ], ], 'ckeditor5_list' => [ 'reversed' => FALSE, 'startIndex' => TRUE, ], ], ], 'expected_superset' => '<br> <p>', Loading Loading @@ -1259,6 +1263,10 @@ public function provider() { 'heading6', ], ], 'ckeditor5_list' => [ 'reversed' => FALSE, 'startIndex' => TRUE, ], 'ckeditor5_sourceEditing' => [ 'allowed_tags' => [ '<cite>', Loading @@ -1276,10 +1284,6 @@ public function provider() { '<h6 id>', ], ], 'ckeditor5_list' => [ 'reversed' => FALSE, 'startIndex' => TRUE, ], ], ], 'expected_superset' => '<br> <p>', Loading Loading @@ -1366,6 +1370,11 @@ public function provider() { ], ], 'plugins' => [ 'ckeditor5_sourceEditing' => [ 'allowed_tags' => [ '<span>', ], ], 'ckeditor5_style' => [ 'styles' => [ [ Loading @@ -1374,11 +1383,6 @@ public function provider() { ], ], ], 'ckeditor5_sourceEditing' => [ 'allowed_tags' => [ '<span>', ], ], ], ], 'expected_superset' => '', Loading core/profiles/standard/config/install/editor.editor.basic_html.yml +5 −5 Original line number Diff line number Diff line Loading @@ -33,6 +33,11 @@ settings: - heading4 - heading5 - heading6 ckeditor5_imageResize: allow_resize: true ckeditor5_list: reversed: false startIndex: true ckeditor5_sourceEditing: allowed_tags: - '<cite>' Loading @@ -49,11 +54,6 @@ settings: - '<h5 id>' - '<h6 id>' - '<span>' ckeditor5_list: reversed: false startIndex: true ckeditor5_imageResize: allow_resize: true image_upload: status: true scheme: public Loading Loading
core/modules/ckeditor5/ckeditor5.post_update.php +24 −0 Original line number Diff line number Diff line Loading @@ -65,3 +65,27 @@ function ckeditor5_post_update_image_toolbar_item(&$sandbox = []) { $config_entity_updater->update($sandbox, 'editor', $callback); } /** * Updates Text Editors using CKEditor 5 to sort plugin settings by plugin key. */ function ckeditor5_post_update_plugins_settings_export_order(&$sandbox = []) { $config_entity_updater = \Drupal::classResolver(ConfigEntityUpdater::class); $config_entity_updater->update($sandbox, 'editor', function (Editor $editor): bool { // Only try to update editors using CKEditor 5. if ($editor->getEditor() !== 'ckeditor5') { return FALSE; } $settings = $editor->getSettings(); // Nothing to do if there are fewer than two plugins with settings. if (count($settings['plugins']) < 2) { return FALSE; } ksort($settings['plugins']); $editor->setSettings($settings); return TRUE; }); }
core/modules/ckeditor5/config/schema/ckeditor5.schema.yml +6 −0 Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ editor.settings.ckeditor5: mapping: items: type: sequence orderby: ~ label: 'Items' sequence: type: ckeditor5.toolbar_item Loading @@ -20,6 +21,7 @@ editor.settings.ckeditor5: plugins: type: sequence label: 'Plugins' orderby: key sequence: type: ckeditor5.plugin.[%key] constraints: Loading Loading @@ -51,6 +53,7 @@ ckeditor5.plugin.ckeditor5_heading: mapping: enabled_headings: type: sequence orderby: value label: 'Enabled Headings' constraints: NotBlank: Loading Loading @@ -80,6 +83,7 @@ ckeditor5.plugin.ckeditor5_sourceEditing: mapping: allowed_tags: type: sequence orderby: ~ label: 'Allowed Tags' sequence: type: ckeditor5.element Loading @@ -95,6 +99,7 @@ ckeditor5.plugin.ckeditor5_alignment: mapping: enabled_alignments: type: sequence orderby: value label: 'Enabled Alignments' constraints: NotBlank: Loading Loading @@ -143,6 +148,7 @@ ckeditor5.plugin.ckeditor5_style: mapping: styles: type: sequence orderby: ~ label: 'Styles' constraints: NotBlank: Loading
core/modules/ckeditor5/tests/src/Functional/Update/CKEditor5UpdatePluginSettingsSortTest.php 0 → 100644 +69 −0 Original line number Diff line number Diff line <?php namespace Drupal\Tests\ckeditor5\Functional\Update; use Drupal\editor\Entity\Editor; use Drupal\FunctionalTests\Update\UpdatePathTestBase; /** * @covers ckeditor5_post_update_plugins_settings_export_order() * @group Update * @group ckeditor5 */ class CKEditor5UpdatePluginSettingsSortTest extends UpdatePathTestBase { /** * {@inheritdoc} */ protected $defaultTheme = 'stark'; /** * {@inheritdoc} */ protected function setDatabaseDumpFiles() { $this->databaseDumpFiles = [ __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-9.4.0.filled.standard.php.gz', ]; } /** * Ensure settings for CKEditor 5 plugins are sorted by plugin key. */ public function testUpdatePluginSettingsSortPostUpdate(): void { $editor = Editor::load('basic_html'); $settings = $editor->getSettings(); $plugin_settings_before = array_keys($settings['plugins']); $this->runUpdates(); $editor = Editor::load('basic_html'); $settings = $editor->getSettings(); $plugin_settings_after = array_keys($settings['plugins']); // Different sort before and after, but the same values. $this->assertNotSame($plugin_settings_before, $plugin_settings_after); sort($plugin_settings_before); $this->assertSame($plugin_settings_before, $plugin_settings_after); } /** * Ensure settings for CKEditor 5 plugins are sorted by plugin key. */ public function testUpdatePluginSettingsSortEntitySave(): void { $editor = Editor::load('basic_html'); $settings = $editor->getSettings(); $plugin_settings_before = array_keys($settings['plugins']); $editor->save(); $editor = Editor::load('basic_html'); $settings = $editor->getSettings(); $plugin_settings_after = array_keys($settings['plugins']); // Different sort before and after, but the same values. $this->assertNotSame($plugin_settings_before, $plugin_settings_after); sort($plugin_settings_before); $this->assertSame($plugin_settings_before, $plugin_settings_after); } }
core/modules/ckeditor5/tests/src/Kernel/SmartDefaultSettingsTest.php +18 −14 Original line number Diff line number Diff line Loading @@ -497,6 +497,10 @@ public function test(string $format_id, array $filters_to_drop, array $expected_ $updated_text_editor->toArray() ); // Save this to ensure the config export order is applied. // @see \Drupal\Core\Config\StorableConfigBase::castValue() $updated_text_editor->save(); // We should now have the expected data in the Editor config entity. $this->assertSame('ckeditor5', $updated_text_editor->getEditor()); $this->assertSame($expected_ckeditor5_settings, $updated_text_editor->getSettings()); Loading Loading @@ -922,12 +926,12 @@ public function provider() { ), ], 'plugins' => array_merge( $basic_html_test_case['expected_ckeditor5_settings']['plugins'], [ 'ckeditor5_alignment' => [ 'enabled_alignments' => ['center', 'justify'], ], ], $basic_html_test_case['expected_ckeditor5_settings']['plugins'], ), ], 'expected_superset' => implode(' ', [ Loading Loading @@ -1124,6 +1128,10 @@ public function provider() { 'heading6', ], ], 'ckeditor5_list' => [ 'reversed' => FALSE, 'startIndex' => TRUE, ], 'ckeditor5_sourceEditing' => [ 'allowed_tags' => [ '<cite>', Loading @@ -1141,10 +1149,6 @@ public function provider() { '<h6 id>', ], ], 'ckeditor5_list' => [ 'reversed' => FALSE, 'startIndex' => TRUE, ], ], ], 'expected_superset' => '<br> <p>', Loading Loading @@ -1259,6 +1263,10 @@ public function provider() { 'heading6', ], ], 'ckeditor5_list' => [ 'reversed' => FALSE, 'startIndex' => TRUE, ], 'ckeditor5_sourceEditing' => [ 'allowed_tags' => [ '<cite>', Loading @@ -1276,10 +1284,6 @@ public function provider() { '<h6 id>', ], ], 'ckeditor5_list' => [ 'reversed' => FALSE, 'startIndex' => TRUE, ], ], ], 'expected_superset' => '<br> <p>', Loading Loading @@ -1366,6 +1370,11 @@ public function provider() { ], ], 'plugins' => [ 'ckeditor5_sourceEditing' => [ 'allowed_tags' => [ '<span>', ], ], 'ckeditor5_style' => [ 'styles' => [ [ Loading @@ -1374,11 +1383,6 @@ public function provider() { ], ], ], 'ckeditor5_sourceEditing' => [ 'allowed_tags' => [ '<span>', ], ], ], ], 'expected_superset' => '', Loading
core/profiles/standard/config/install/editor.editor.basic_html.yml +5 −5 Original line number Diff line number Diff line Loading @@ -33,6 +33,11 @@ settings: - heading4 - heading5 - heading6 ckeditor5_imageResize: allow_resize: true ckeditor5_list: reversed: false startIndex: true ckeditor5_sourceEditing: allowed_tags: - '<cite>' Loading @@ -49,11 +54,6 @@ settings: - '<h5 id>' - '<h6 id>' - '<span>' ckeditor5_list: reversed: false startIndex: true ckeditor5_imageResize: allow_resize: true image_upload: status: true scheme: public Loading