function CKEditor5StylesheetsMessage::getWarning

Same name in other branches
  1. 9 core/modules/ckeditor5/src/CKEditor5StylesheetsMessage.php \Drupal\ckeditor5\CKEditor5StylesheetsMessage::getWarning()
  2. 11.x core/modules/ckeditor5/src/CKEditor5StylesheetsMessage.php \Drupal\ckeditor5\CKEditor5StylesheetsMessage::getWarning()

Generates a warning related to ckeditor_stylesheets.

Identifies themes using ckeditor_stylesheets without an equivalent ckeditor5-stylesheets setting. If such themes are found, a warning message is returned.

Return value

\Drupal\Core\StringTranslation\PluralTranslatableMarkup|null A warning message where appropriate, otherwise null.

File

core/modules/ckeditor5/src/CKEditor5StylesheetsMessage.php, line 62

Class

CKEditor5StylesheetsMessage
Messaging for themes using the ckeditor_stylesheets setting.

Namespace

Drupal\ckeditor5

Code

public function getWarning() {
    $themes = [];
    $default_theme = $this->configFactory
        ->get('system.theme')
        ->get('default');
    if (!empty($default_theme)) {
        $themes[$default_theme] = $this->themeHandler
            ->listInfo()[$default_theme]->info;
    }
    $admin_theme = $this->configFactory
        ->get('system.theme')
        ->get('admin');
    if (!empty($admin_theme) && $admin_theme !== $default_theme) {
        $themes[$admin_theme] = $this->themeHandler
            ->listInfo()[$admin_theme]->info;
    }
    // Collect information on which themes/base themes have ckeditor_stylesheets
    // configuration, but do not have corresponding ckeditor5-stylesheets
    // configuration.
    $ckeditor_stylesheets_use = [];
    foreach ($themes as $theme_info) {
        $this->checkForStylesheetsEquivalent($theme_info, $ckeditor_stylesheets_use);
    }
    if (!empty($ckeditor_stylesheets_use)) {
        // A subtheme may unnecessarily appear multiple times.
        $ckeditor_stylesheets_use = array_unique($ckeditor_stylesheets_use);
        $last_item = array_pop($ckeditor_stylesheets_use);
        $stylesheets_warning = $this->formatPlural(count($ckeditor_stylesheets_use) + 1, 'The %last_item theme has ckeditor_stylesheets configured without a corresponding ckeditor5-stylesheets configuration. See the <a href=":change_record">change record</a> for details.', 'The %first_items and %last_item themes have ckeditor_stylesheets configured, but without corresponding ckeditor5-stylesheets configurations. See the <a href=":change_record">change record</a> for details.', [
            '%last_item' => $last_item,
            '%first_items' => implode(', ', $ckeditor_stylesheets_use),
            ':change_record' => 'https://www.drupal.org/node/3259165',
        ]);
        return $stylesheets_warning;
    }
    return NULL;
}

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