public function CKEditor::getJSSettings in Drupal 10
Same name and namespace in other branches
- 8 core/modules/ckeditor/src/Plugin/Editor/CKEditor.php \Drupal\ckeditor\Plugin\Editor\CKEditor::getJSSettings()
- 9 core/modules/ckeditor/src/Plugin/Editor/CKEditor.php \Drupal\ckeditor\Plugin\Editor\CKEditor::getJSSettings()
File
- core/
modules/ ckeditor/ src/ Plugin/ Editor/ CKEditor.php, line 313
Class
- CKEditor
- Defines a CKEditor-based text editor for Drupal.
Namespace
Drupal\ckeditor\Plugin\EditorCode
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.
$settings += [
'drupalExternalPlugins' => array_map([
$this->fileUrlGenerator,
'generateString',
], $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;
}