From 6f5a6eaf479e8bf096d51bbdbf521b6d1a21f6c7 Mon Sep 17 00:00:00 2001 From: Lauri Eskola Date: Mon, 21 Mar 2022 10:43:45 +0200 Subject: [PATCH] Issue #3259443 by marcvangend, bnjmnm, Abhijith S: Plugin settings do not appear when a configurable plugin is added AFTER removing all buttons (cherry picked from commit 7a1c45f38e03860592e70b8aef0235e6ad6f332f) (cherry picked from commit 15011eb13c0b13218415fc013b548ba3fdf5a0f6) --- core/modules/ckeditor5/ckeditor5.module | 13 +++++-- .../src/FunctionalJavascript/AdminUiTest.php | 36 +++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/core/modules/ckeditor5/ckeditor5.module b/core/modules/ckeditor5/ckeditor5.module index 9bc27675e3a..06029a810c3 100644 --- a/core/modules/ckeditor5/ckeditor5.module +++ b/core/modules/ckeditor5/ckeditor5.module @@ -229,10 +229,19 @@ function ckeditor5_form_filter_format_form_alter(array &$form, FormStateInterfac $form['filter_settings']['#wrapper_attributes']['id'] = 'filter-settings-wrapper'; // Add an ID to the editor settings vertical tabs wrapper so it can be easily - // targeted by JavaScript. + // targeted by JavaScript. If there are no configurable plugins, render an + // empty container with the same ID instead. // @todo consider moving this to editor.module when this module is moved to // Drupal core https://www.drupal.org/project/ckeditor5/issues/3231322. - $form['editor']['settings']['subform']['plugin_settings']['#wrapper_attributes']['id'] = 'plugin-settings-wrapper'; + if (!empty($form['editor']['settings']['subform']['plugins'])) { + $form['editor']['settings']['subform']['plugin_settings']['#wrapper_attributes']['id'] = 'plugin-settings-wrapper'; + } + else { + $form['editor']['settings']['subform']['plugin_settings'] = [ + '#type' => 'container', + '#attributes' => ['id' => 'plugin-settings-wrapper'], + ]; + } $form['#after_build'][] = [CKEditor5::class, 'assessActiveTextEditorAfterBuild']; $form['#validate'][] = [CKEditor5::class, 'validateSwitchingToCKEditor5']; diff --git a/core/modules/ckeditor5/tests/src/FunctionalJavascript/AdminUiTest.php b/core/modules/ckeditor5/tests/src/FunctionalJavascript/AdminUiTest.php index 9f655886cde..cb3e3135108 100644 --- a/core/modules/ckeditor5/tests/src/FunctionalJavascript/AdminUiTest.php +++ b/core/modules/ckeditor5/tests/src/FunctionalJavascript/AdminUiTest.php @@ -2,6 +2,8 @@ namespace Drupal\Tests\ckeditor5\FunctionalJavascript; +// cspell:ignore sourceediting + /** * Tests for CKEditor 5 in the admin UI. * @@ -170,6 +172,40 @@ class AdminUiTest extends CKEditor5TestBase { $this->assertCount(1, $find_validation_error_messages()); } + /** + * Tests the plugin settings form section. + */ + public function testPluginSettingsFormSection() { + $page = $this->getSession()->getPage(); + $assert_session = $this->assertSession(); + + $this->createNewTextFormat($page, $assert_session); + $assert_session->assertWaitOnAjaxRequest(); + + // The default toolbar only enables the configurable heading plugin and the + // non-configurable bold and italic plugins. + $assert_session->fieldValueEquals('editor[settings][toolbar][items]', '["heading","bold","italic"]'); + // The heading plugin config form should be present. + $assert_session->elementExists('css', '[data-drupal-selector="edit-editor-settings-plugins-ckeditor5-heading"]'); + + // Remove the heading plugin from the toolbar. + $this->triggerKeyUp('.ckeditor5-toolbar-item-heading', 'ArrowUp'); + $assert_session->assertWaitOnAjaxRequest(); + + // The heading plugin config form should no longer be present. + $assert_session->elementNotExists('css', '[data-drupal-selector="edit-editor-settings-plugins-ckeditor5-heading"]'); + // The plugin settings wrapper should still be present, but empty. + $assert_session->elementExists('css', '#plugin-settings-wrapper'); + $assert_session->elementNotContains('css', '#plugin-settings-wrapper', 'triggerKeyUp('.ckeditor5-toolbar-item-sourceEditing', 'ArrowDown'); + $assert_session->assertWaitOnAjaxRequest(); + + // The source plugin config form should be present. + $assert_session->elementExists('css', '[data-drupal-selector="edit-editor-settings-plugins-ckeditor5-sourceediting"]'); + } + /** * Tests the language config form. */