function CKEditor::getJSSettings

Same name in other branches
  1. 9 core/modules/ckeditor/src/Plugin/Editor/CKEditor.php \Drupal\ckeditor\Plugin\Editor\CKEditor::getJSSettings()

Overrides EditorPluginInterface::getJSSettings

1 call to CKEditor::getJSSettings()
CKEditor::buildConfigurationForm in core/modules/ckeditor/src/Plugin/Editor/CKEditor.php
Form constructor.

File

core/modules/ckeditor/src/Plugin/Editor/CKEditor.php, line 275

Class

CKEditor
Defines a CKEditor-based text editor for Drupal.

Namespace

Drupal\ckeditor\Plugin\Editor

Code

public function getJSSettings(Editor $editor) {
    $settings = [];
    // Get the settings for all enabled plugins, even the internal ones.
    $enabled_plugins = array_keys($this->ckeditorPluginManager
        ->getEnabledPluginFiles($editor, TRUE));
    foreach ($enabled_plugins as $plugin_id) {
        $plugin = $this->ckeditorPluginManager
            ->createInstance($plugin_id);
        $settings += $plugin->getConfig($editor);
    }
    // Fall back on English if no matching language code was found.
    $display_langcode = 'en';
    // Map the interface language code to a CKEditor translation if interface
    // translation is enabled.
    if ($this->moduleHandler
        ->moduleExists('locale')) {
        $ckeditor_langcodes = $this->getLangcodes();
        $language_interface = $this->languageManager
            ->getCurrentLanguage();
        if (isset($ckeditor_langcodes[$language_interface->getId()])) {
            $display_langcode = $ckeditor_langcodes[$language_interface->getId()];
        }
    }
    // Next, set the most fundamental CKEditor settings.
    $external_plugin_files = $this->ckeditorPluginManager
        ->getEnabledPluginFiles($editor);
    $settings += [
        'toolbar' => $this->buildToolbarJSSetting($editor),
        'contentsCss' => $this->buildContentsCssJSSetting($editor),
        'extraPlugins' => implode(',', array_keys($external_plugin_files)),
        'language' => $display_langcode,
        // Configure CKEditor to not load styles.js. The StylesCombo plugin will
        // set stylesSet according to the user's settings, if the "Styles" button
        // is enabled. We cannot get rid of this until CKEditor will stop loading
        // styles.js by default.
        // See http://dev.ckeditor.com/ticket/9992#comment:9.
'stylesSet' => FALSE,
    ];
    // Finally, set Drupal-specific CKEditor settings.
    $root_relative_file_url = function ($uri) {
        return file_url_transform_relative(file_create_url($uri));
    };
    $settings += [
        'drupalExternalPlugins' => array_map($root_relative_file_url, $external_plugin_files),
    ];
    // Parse all CKEditor plugin JavaScript files for translations.
    if ($this->moduleHandler
        ->moduleExists('locale')) {
        locale_js_translate(array_values($external_plugin_files));
    }
    ksort($settings);
    return $settings;
}

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