Commit 9c7aa8ad authored by Lauri Timmanee's avatar Lauri Timmanee Committed by Ben Mullins
Browse files

Issue #3194084 by bnjmnm, Wim Leers, lauriii, hooroomoo, Gábor Hojtsy: Support...

Issue #3194084 by bnjmnm, Wim Leers, lauriii, hooroomoo, Gábor Hojtsy: Support functionality equivalent to ckeditor_stylesheets
parent f7e9db42
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -29,8 +29,17 @@ drupal.ckeditor5:
    - core/ckeditor5.editorDecoupled
    - core/ckeditor5
    - editor/drupal.editor
    - ckeditor5/drupal.ckeditor5.quickedit-temporary-work-around
    - ckeditor5/ie11.user.warnings
    - ckeditor5/drupal.ckeditor5.stylesheets
    - core/drupalSettings
    - core/drupal.message

# Library used for dynamically loading CKEditor 5 stylesheets from the default
# front end theme.
# @see ckeditor5_library_info_alter()
drupal.ckeditor5.stylesheets:
  version: VERSION
  css: []

drupal.ckeditor5.quickedit-temporary-work-around:
  deprecated: "Temporary work-around until https://www.drupal.org/project/drupal/issues/3196689 lands."
@@ -103,6 +112,8 @@ drupal.ckeditor5.filter.admin:
    - core/drupal.message
    - core/once
    - core/drupal.ajax
    - core/drupalSettings
    - core/drupal.message

admin:
  js:
+58 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
declare(strict_types = 1);

use Drupal\ckeditor5\Plugin\Editor\CKEditor5;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\InvokeCommand;
use Drupal\Core\Ajax\MessageCommand;
@@ -392,6 +393,22 @@ function ckeditor5_library_info_alter(&$libraries, $extension) {
  }

  $moduleHandler = \Drupal::moduleHandler();

  if ($extension === 'ckeditor5') {
    // Add paths to stylesheets specified by a theme's ckeditor5-stylesheets
    // config property.
    $css = _ckeditor5_theme_css();
    $libraries['drupal.ckeditor5.stylesheets'] = [
      'css' => [
        'theme' => array_fill_keys(array_values($css), []),
      ],
    ];

    if ($moduleHandler->moduleExists('quickedit')) {
      $libraries['drupal.ckeditor5']['dependencies'][] = 'ckeditor5/drupal.ckeditor5.quickedit-temporary-work-around';
    }
  }

  // Only add translation processing if the locale module is enabled.
  if (!$moduleHandler->moduleExists('locale')) {
    return;
@@ -558,3 +575,44 @@ function ckeditor5_config_schema_info_alter(&$definitions) {
  // @see @see editor.editor.*.image_upload
  $definitions['ckeditor5_valid_pair__format_and_editor']['mapping']['image_upload'] = $definitions['editor.editor.*']['mapping']['image_upload'];
}

/**
 * Retrieves the default theme's CKEditor 5 stylesheets.
 *
 * Themes may specify CSS files for use within CKEditor 5 by including a
 * "ckeditor5-stylesheets" key in their .info.yml file.
 *
 * @code
 * ckeditor5-stylesheets:
 *   - css/ckeditor.css
 * @endcode
 *
 * @return string[]
 *   A list of paths to CSS files.
 */
function _ckeditor5_theme_css($theme = NULL): array {
  $css = [];
  if (!isset($theme)) {
    $theme = \Drupal::config('system.theme')->get('default');
  }
  if (isset($theme) && $theme_path = \Drupal::service('extension.list.theme')->getPath($theme)) {
    $info = \Drupal::service('extension.list.theme')->getExtensionInfo($theme);
    if (isset($info['ckeditor5-stylesheets'])) {
      $css = $info['ckeditor5-stylesheets'];
      foreach ($css as $key => $url) {
        // CSS url is external or relative to Drupal root.
        if (UrlHelper::isExternal($url) || $url[0] === '/') {
          $css[$key] = $url;
        }
        // CSS url is relative to theme.
        else {
          $css[$key] = '/' . $theme_path . '/' . $url;
        }
      }
    }
    if (isset($info['base theme'])) {
      $css = array_merge(_ckeditor5_theme_css($info['base theme']), $css);
    }
  }
  return $css;
}
+10 −0
Original line number Diff line number Diff line
@@ -13,3 +13,13 @@ services:
      - '@plugin.manager.ckeditor5.plugin'
      - '@plugin.manager.ckeditor4to5upgrade.plugin'
      - '@?plugin.manager.ckeditor.plugin'
  ckeditor5.stylesheets.message:
    class: Drupal\ckeditor5\CKEditor5StylesheetsMessage
    arguments:
      - '@theme_handler'
      - '@config.factory'
  ckeditor5.ckeditor5_cache_tag:
    class: Drupal\ckeditor5\EventSubscriber\CKEditor5CacheTag
    arguments: ['@cache_tags.invalidator']
    tags:
      - { name: event_subscriber }
+1 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@

        // Add a container for messages above the text format select element.
        const selectMessageContainer = document.createElement('div');
        select.parentNode.insertBefore(selectMessageContainer, select);
        select.parentNode.after(selectMessageContainer, select);
        const selectMessages = new Drupal.Message(selectMessageContainer);
        const editorSettings = document.querySelector(
          '#editor-settings-wrapper',
+1 −1
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
      if (typeof editorSelect[0] !== 'undefined') {
        var select = editorSelect[0];
        var selectMessageContainer = document.createElement('div');
        select.parentNode.insertBefore(selectMessageContainer, select);
        select.parentNode.after(selectMessageContainer, select);
        var selectMessages = new Drupal.Message(selectMessageContainer);
        var editorSettings = document.querySelector('#editor-settings-wrapper');

Loading