function SmartDefaultSettings::computeSubsetSettingForEnabledPluginsWithSubsets

Same name in other branches
  1. 10 core/modules/ckeditor5/src/SmartDefaultSettings.php \Drupal\ckeditor5\SmartDefaultSettings::computeSubsetSettingForEnabledPluginsWithSubsets()

Computes configuration for all enabled CKEditor 5 plugins with subsets.

Parameters

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

\Drupal\filter\FilterFormatInterface $text_format: The text format for which to compute smart default settings.

1 call to SmartDefaultSettings::computeSubsetSettingForEnabledPluginsWithSubsets()
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 956

Class

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

Namespace

Drupal\ckeditor5

Code

private function computeSubsetSettingForEnabledPluginsWithSubsets(EditorInterface $editor, FilterFormatInterface $text_format) : void {
    $settings = $editor->getSettings();
    $update_settings = FALSE;
    $enabled_definitions = $this->pluginManager
        ->getEnabledDefinitions($editor);
    $configurable_subset_definitions = array_filter($enabled_definitions, function (CKEditor5PluginDefinition $definition) : bool {
        return is_a($definition->getClass(), CKEditor5PluginElementsSubsetInterface::class, TRUE);
    });
    foreach ($configurable_subset_definitions as $plugin_name => $definition) {
        // Skip Source Editing as that has already been configured.
        if ($plugin_name === 'ckeditor5_sourceEditing') {
            continue;
        }
        try {
            $subset_configuration = $this->upgradePluginManager
                ->computeCKEditor5PluginSubsetConfiguration($plugin_name, $text_format);
        } catch (\OutOfBoundsException $e) {
            $messages[MessengerInterface::TYPE_WARNING][] = $this->t('The CKEditor 5 plugin %button has a configurable subset of elements, but does not have a known upgrade path to configure that subset to match your text format. Hence it is now using its default configuration.', [
                '%plugin' => $plugin_name,
            ]);
            continue;
        }
        if ($subset_configuration) {
            $update_settings = TRUE;
            assert(isset($settings['plugins'][$plugin_name]));
            $default_configuration = $settings['plugins'][$plugin_name];
            // The subset configuration's key-value pairs must override those of the
            // default configuration.
            $settings['plugins'][$plugin_name] = $subset_configuration + $default_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.