Commit 6d257baa authored by catch's avatar catch
Browse files

fix: #3403394 [regression] CKEditor 5 throws an exception when the default theme is not installed

By: berdir
By: marvil07
By: lauriii
By: smustgrave
By: wim leers
By: gábor hojtsy
By: catch
By: quietone
(cherry picked from commit 08958d1e)
parent 546eba73
Loading
Loading
Loading
Loading
Loading
+6
Changes for core/modules/ckeditor5/src/Hook/Ckeditor5Hooks.php: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -640,6 +640,12 @@ protected function themeCss(?string $theme = NULL): array {
    if (!isset($theme)) {
      $theme = $this->configFactory->get('system.theme')->get('default');
    }
    // The theme may not be installed yet. For example, the installer installs
    // modules before themes. Theme CSS for CKEditor 5 is optional, so leave it
    // out until the theme is installed.
    if (isset($theme) && !isset($this->themeExtensionList->getAllInstalledInfo()[$theme])) {
      return $css;
    }
    if (isset($theme) && $theme_path = $this->themeExtensionList->getPath($theme)) {
      $info = $this->themeExtensionList->getExtensionInfo($theme);
      if (isset($info['ckeditor5-stylesheets']) && $info['ckeditor5-stylesheets'] !== FALSE) {
+6
Changes for core/modules/ckeditor5/tests/modules/ckeditor5_config_install_test/ckeditor5_config_install_test.info.yml: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
name: CKEditor 5 config install test
type: module
description: "Ships a CKEditor 5 text editor in its default configuration."
package: Testing
dependencies:
  - ckeditor5:ckeditor5
+16
Changes for core/modules/ckeditor5/tests/modules/ckeditor5_config_install_test/config/install/editor.editor.ckeditor5_config_install_test.yml: 16 added lines, 0 removed lines.
Original line number Diff line number Diff line
langcode: en
status: true
dependencies:
  config:
    - filter.format.ckeditor5_config_install_test
  module:
    - ckeditor5
format: ckeditor5_config_install_test
editor: ckeditor5
settings:
  toolbar:
    items:
      - bold
  plugins: {}
image_upload:
  status: false
+16
Changes for core/modules/ckeditor5/tests/modules/ckeditor5_config_install_test/config/install/filter.format.ckeditor5_config_install_test.yml: 16 added lines, 0 removed lines.
Original line number Diff line number Diff line
langcode: en
status: true
dependencies: {}
name: 'CKEditor 5 config install test'
format: ckeditor5_config_install_test
weight: 0
filters:
  filter_html:
    id: filter_html
    provider: filter
    status: true
    weight: 0
    settings:
      allowed_html: '<p> <br> <strong>'
      filter_html_help: false
      filter_html_nofollow: false
+45
Changes for core/modules/ckeditor5/tests/src/Functional/ConfigInstallTest.php: 45 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\Tests\ckeditor5\Functional;

use Drupal\Tests\BrowserTestBase;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;

/**
 * Tests installing a module that ships a CKEditor 5 editor in its config.
 *
 * The test module is installed together with the profile's modules, before
 * any theme is installed. The default theme in system.theme is already set at
 * that point, so CKEditor 5 must not expect it to be installed.
 *
 * @see https://www.drupal.org/project/drupal/issues/3403394
 *
 * @internal
 */
#[Group('ckeditor5')]
#[RunTestsInSeparateProcesses]
class ConfigInstallTest extends BrowserTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = ['ckeditor5_config_install_test'];

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

  /**
   * Tests that the editor config is installed during site install.
   */
  public function testEditorInstalled(): void {
    $editor = \Drupal::entityTypeManager()->getStorage('editor')->load('ckeditor5_config_install_test');
    $this->assertNotNull($editor);
    $this->assertSame('ckeditor5', $editor->getEditor());
  }

}