diff --git a/core/modules/ckeditor5/ckeditor5.libraries.yml b/core/modules/ckeditor5/ckeditor5.libraries.yml index d0908635c0..390d8ba230 100644 --- a/core/modules/ckeditor5/ckeditor5.libraries.yml +++ b/core/modules/ckeditor5/ckeditor5.libraries.yml @@ -27,7 +27,6 @@ drupal.ckeditor5: - core/ckeditor5.editorDecoupled - core/ckeditor5 - editor/drupal.editor - - ckeditor5/drupal.ckeditor5.quickedit-temporary-work-around - ckeditor5/drupal.ckeditor5.stylesheets - core/drupalSettings - core/drupal.message @@ -100,6 +99,12 @@ drupal.ckeditor5.filter.admin: - core/drupalSettings - core/drupal.message +drupal.ckeditor5.stylesheets.warning: + drupalSettings: + ckeditor5: + ckeditor4_stylesheets: [] + + admin: js: js/ckeditor5.admin.js: { } diff --git a/core/modules/ckeditor5/ckeditor5.module b/core/modules/ckeditor5/ckeditor5.module index c57091491b..6dddd24b91 100644 --- a/core/modules/ckeditor5/ckeditor5.module +++ b/core/modules/ckeditor5/ckeditor5.module @@ -357,7 +357,7 @@ function ckeditor5_library_info_alter(&$libraries, $extension) { ]; $admin_theme = \Drupal::configFactory()->get('system.theme')->get('admin'); - $admin_theme_info = \Drupal::service('theme_handler')->listInfo()[$admin_theme]->info; + $admin_theme_info = !empty($admin_theme) ? \Drupal::service('theme_handler')->listInfo()[$admin_theme]->info : []; $opt_out_ckeditor5_stylesheets = (isset($admin_theme_info['ckeditor5-stylesheets']) && $admin_theme_info['ckeditor5-info'] !== FALSE); @@ -383,10 +383,16 @@ function ckeditor5_library_info_alter(&$libraries, $extension) { $base_theme = $base_theme_info['base_theme'] ?? FALSE; } if (!empty($ckeditor4_stylesheets)) { - $libraries['drupal.ckeditor5']['drupalSettings']['ckeditor5']['ckeditor4_stylesheets'] = $ckeditor4_stylesheets; - $libraries['drupal.ckeditor5.filter.admin']['drupalSettings']['ckeditor5']['ckeditor4_stylesheets'] = $ckeditor4_stylesheets; + $libraries['drupal.ckeditor5']['dependencies'][] = 'ckeditor5/drupal.ckeditor5.stylesheets.warning'; + $libraries['drupal.ckeditor5.filter.admin']['dependencies'][] = 'ckeditor5/drupal.ckeditor5.stylesheets.warning'; + $libraries['drupal.ckeditor5.stylesheets.warning']['drupalSettings']['ckeditor5']['ckeditor4_stylesheets'] = $ckeditor4_stylesheets; } } + + $moduleHandler = \Drupal::service('module_handler'); + if ($moduleHandler->moduleExists('quickedit')) { + $libraries['drupal.ckeditor5']['dependencies'][] = 'ckeditor5/drupal.ckeditor5.quickedit-temporary-work-around'; + } } if ($extension === 'core') { diff --git a/core/modules/ckeditor5/tests/src/Functional/CKEditor5QuickEditLibraryTest.php b/core/modules/ckeditor5/tests/src/Functional/CKEditor5QuickEditLibraryTest.php new file mode 100644 index 0000000000..6d31fb43a5 --- /dev/null +++ b/core/modules/ckeditor5/tests/src/Functional/CKEditor5QuickEditLibraryTest.php @@ -0,0 +1,92 @@ + 'llama', + 'name' => 'Llama', + 'filters' => [], + 'roles' => [RoleInterface::AUTHENTICATED_ID], + ]); + $filtered_html_format->save(); + $this->editor = Editor::create([ + 'format' => 'llama', + 'editor' => 'ckeditor5', + 'settings' => [ + 'toolbar' => [ + 'items' => [], + ], + ], + ]); + $this->editor->save(); + $this->assertSame([], array_map( + function (ConstraintViolation $v) { + return (string) $v->getMessage(); + }, + iterator_to_array(CKEditor5::validatePair($this->editor, $filtered_html_format)) + )); + // Create node type. + $this->drupalCreateContentType([ + 'type' => 'article', + 'name' => 'Article', + ]); + + $this->adminUser = $this->drupalCreateUser([ + 'create article content', + 'edit own article content', + 'use text format llama', + ]); + $this->drupalLogin($this->adminUser); + } + + public function testQuickeditTemporaryWorkaround() { + $assert_session = $this->assertSession(); + + $this->expectDeprecation('Temporary work-around until https://www.drupal.org/project/drupal/issues/3196689 lands.'); + /** @var \Drupal\Core\Extension\ThemeInstallerInterface $theme_installer */ + $theme_installer = \Drupal::service('theme_installer'); + // Install a theme which has an absolute external CSS URL. + $theme_installer->install(['test_ckeditor_stylesheets_relative']); + $this->config('system.theme')->set('default', 'test_ckeditor_stylesheets_relative')->save(); + $this->config('system.theme')->set('admin', 'stark')->save(); + + $this->drupalGet('node/add/article'); + $assert_session->responseContains('css/quickedit-override.css'); + } + +} diff --git a/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditorStylesheetsWarningTest.php b/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditorStylesheetsWarningTest.php index c9ebbcd373..d743b1d38d 100644 --- a/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditorStylesheetsWarningTest.php +++ b/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditorStylesheetsWarningTest.php @@ -15,11 +15,15 @@ class CKEditorStylesheetsWarningTest extends CKEditor5TestBase { */ protected function setUp(): void { parent::setUp(); + } + + public function installThemeThatTriggersWarning() { $theme_installer = \Drupal::service('theme_installer'); $theme_installer->install(['test_ckeditor_stylesheets_without_5']); $this->config('system.theme')->set('default', 'test_ckeditor_stylesheets_without_5')->save(); $theme_installer->install(['stark']); $this->config('system.theme')->set('admin', 'stark')->save(); + \Drupal::service('theme_handler')->refreshInfo(); } /** @@ -30,7 +34,10 @@ public function testWarningFilterUI() { $assert_session = $this->assertSession(); $this->addNewTextFormat($page, $assert_session); $this->drupalGet('admin/config/content/formats/manage/ckeditor5'); - $assert_session->waitForText('There are CKEditor 4 stylesheets without equivalents'); + $this->assertFalse($assert_session->waitForText('There are CKEditor 4 stylesheets without equivalents', 5000)); + $this->installThemeThatTriggersWarning(); + $this->drupalGet('admin/config/content/formats/manage/ckeditor5'); + $this->assertTrue($assert_session->waitForText('There are CKEditor 4 stylesheets without equivalents')); } /** @@ -41,7 +48,13 @@ public function testWarningEditorInstance() { $assert_session = $this->assertSession(); $this->addNewTextFormat($page, $assert_session); $this->drupalGet('node/add'); - $assert_session->waitForText('There are CKEditor 4 stylesheets that may need CKeditor 5 equivalents.'); + $this->assertFalse($assert_session->waitForText('There are CKEditor 4 stylesheets that may need CKeditor 5 equivalents.', 5000)); + $this->installThemeThatTriggersWarning(); + + // Go somewhere other than node/add to ensure hook_libraries is updated. + $this->drupalGet('admin/config/content/formats/manage/ckeditor5'); + $this->drupalGet('node/add'); + $this->assertTrue($assert_session->waitForText('There are CKEditor 4 stylesheets that may need CKeditor 5 equivalents.')); } }