function SmartDefaultSettings::addDefaultSettingsForEnabledConfigurablePlugins

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

Adds default settings for all enabled CKEditor 5 plugins.

Parameters

\Drupal\editor\EditorInterface $editor: The text editor config entity to update.

1 call to SmartDefaultSettings::addDefaultSettingsForEnabledConfigurablePlugins()
SmartDefaultSettings::computeSmartDefaultSettings in core/modules/ckeditor5/src/SmartDefaultSettings.php
Computes the closest possible equivalent settings for switching to CKEditor 5.

File

core/modules/ckeditor5/src/SmartDefaultSettings.php, line 922

Class

SmartDefaultSettings
Generates CKEditor 5 settings for existing text editors/formats.

Namespace

Drupal\ckeditor5

Code

private function addDefaultSettingsForEnabledConfigurablePlugins(EditorInterface $editor) : void {
    $settings = $editor->getSettings();
    $update_settings = FALSE;
    $enabled_definitions = $this->pluginManager
        ->getEnabledDefinitions($editor);
    $configurable_definitions = array_filter($enabled_definitions, function (CKEditor5PluginDefinition $definition) : bool {
        return $definition->isConfigurable();
    });
    foreach ($configurable_definitions as $plugin_name => $definition) {
        $default_plugin_configuration = $this->pluginManager
            ->getPlugin($plugin_name, NULL)
            ->defaultConfiguration();
        // Skip plugins with an empty default configuration, the plugin
        // configuration is most likely stored elsewhere. Also skip any plugin
        // that already has configuration data as default values are not needed.
        if ($default_plugin_configuration === [] || isset($settings['plugins'][$plugin_name])) {
            continue;
        }
        $update_settings = TRUE;
        $settings['plugins'][$plugin_name] = $default_plugin_configuration;
    }
    if ($update_settings) {
        $editor->setSettings($settings);
    }
}

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