You are here

function _ckeditor5_theme_css in Drupal 10

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.


ckeditor5-stylesheets:
  - css/ckeditor.css

Return value

string[] A list of paths to CSS files.

2 calls to _ckeditor5_theme_css()
CKEditor5StylesheetsTest::testExternalStylesheets in core/modules/ckeditor5/tests/src/Kernel/CKEditor5StylesheetsTest.php
Tests loading of theme's CKEditor 5 stylesheets defined in the .info file.
ckeditor5_library_info_alter in core/modules/ckeditor5/ckeditor5.module
Implements hook_library_info_alter().

File

core/modules/ckeditor5/ckeditor5.module, line 634

Code

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;
        }
        else {
          $css[$key] = '/' . $theme_path . '/' . $url;
        }
      }
    }
    if (isset($info['base theme'])) {
      $css = array_merge(_ckeditor5_theme_css($info['base theme']), $css);
    }
  }
  return $css;
}