You are here

function _ckeditor_theme_css in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/ckeditor/ckeditor.module \_ckeditor_theme_css()

Retrieves the default theme's CKEditor stylesheets.

Themes may specify iframe-specific CSS files for use with CKEditor by including a "ckeditor_stylesheets" key in their .info.yml file.

ckeditor_stylesheets:
-css / ckeditor - iframe . css;
2 calls to _ckeditor_theme_css()
CKEditor::buildContentsCssJSSetting in core/modules/ckeditor/src/Plugin/Editor/CKEditor.php
Builds the "contentsCss" configuration part of the CKEditor JS settings.
CKEditorTest::testExternalStylesheets in core/modules/ckeditor/tests/src/Kernel/CKEditorTest.php
Tests loading of theme's CKEditor stylesheets defined in the .info file.

File

core/modules/ckeditor/ckeditor.module, line 89
Provides integration with the CKEditor WYSIWYG editor.

Code

function _ckeditor_theme_css($theme = NULL) {
  $css = [];
  if (!isset($theme)) {
    $theme = \Drupal::config('system.theme')
      ->get('default');
  }

  /** @var \Drupal\Core\Extension\ThemeExtensionList $theme_list */
  $theme_list = \Drupal::service('extension.list.theme');
  if (isset($theme) && ($theme_path = $theme_list
    ->getPath($theme))) {
    $info = $theme_list
      ->getExtensionInfo($theme);
    if (isset($info['ckeditor_stylesheets'])) {
      $css = $info['ckeditor_stylesheets'];
      foreach ($css as $key => $url) {

        // CSS url is external.
        if (UrlHelper::isExternal($url)) {
          $css[$key] = $url;
        }
        elseif ($url[0] === '/') {
          $css[$key] = substr($url, 1);
        }
        else {
          $css[$key] = $theme_path . '/' . $url;
        }
      }
    }
    if (isset($info['base theme'])) {
      $css = array_merge(_ckeditor_theme_css($info['base theme']), $css);
    }
  }
  return $css;
}