public function CKEditor::getJSSettings in Drupal 9
Same name and namespace in other branches
- 8 core/modules/ckeditor/src/Plugin/Editor/CKEditor.php \Drupal\ckeditor\Plugin\Editor\CKEditor::getJSSettings()
Returns JavaScript settings to be attached.
Most text editors use JavaScript to provide a WYSIWYG or toolbar on the client-side interface. This method can be used to convert internal settings of the text editor into JavaScript variables that will be accessible when the text editor is loaded.
Parameters
\Drupal\editor\Entity\Editor $editor: A configured text editor object.
Return value
array An array of settings that will be added to the page for use by this text editor's JavaScript integration.
Overrides EditorPluginInterface::getJSSettings
See also
\Drupal\Core\Render\AttachmentsResponseProcessorInterface::processAttachments()
EditorManager::getAttachments()
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 303
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;
}