function Ckeditor5Hooks::themeCss

Same name and namespace in other branches
  1. main core/modules/ckeditor5/src/Hook/Ckeditor5Hooks.php \Drupal\ckeditor5\Hook\Ckeditor5Hooks::themeCss()

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

Parameters

string|null $theme: (optional) The theme. If omitted, the default theme is considered.

Return value

string[] A list of paths to CSS files.

1 call to Ckeditor5Hooks::themeCss()
Ckeditor5Hooks::libraryInfoAlter in core/modules/ckeditor5/src/Hook/Ckeditor5Hooks.php
Implements hook_library_info_alter().

File

core/modules/ckeditor5/src/Hook/Ckeditor5Hooks.php, line 646

Class

Ckeditor5Hooks
Hook implementations for ckeditor5.

Namespace

Drupal\ckeditor5\Hook

Code

protected function themeCss(?string $theme = NULL) : array {
  $css = [];
  if (!isset($theme)) {
    $theme = $this->configFactory
      ->get('system.theme')
      ->get('default');
  }
  if (isset($theme) && $theme_path = $this->themeExtensionList
    ->getPath($theme)) {
    $info = $this->themeExtensionList
      ->getExtensionInfo($theme);
    if (isset($info['ckeditor5-stylesheets']) && $info['ckeditor5-stylesheets'] !== FALSE) {
      $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($this->themeCss($info['base theme']), $css);
    }
  }
  return $css;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.