You are here

public function CKEditor5PluginManager::getCKEditor5PluginConfig in Drupal 10

Gets the configuration for the CKEditor 5 plugins enabled in this editor.

Parameters

\Drupal\editor\EditorInterface $editor: A configured text editor object.

Return value

array[] An array with two key-value pairs: 1. 'plugins' lists all plugins to load 2. 'config' lists the configuration for all these plugins.

Overrides CKEditor5PluginManagerInterface::getCKEditor5PluginConfig

See also

https://ckeditor.com/docs/ckeditor5/latest/api/module_editor-classic_cla...

\Drupal\ckeditor5\Plugin\Editor\CKEditor5::getJSSettings()

File

core/modules/ckeditor5/src/Plugin/CKEditor5PluginManager.php, line 263

Class

CKEditor5PluginManager
Provides a CKEditor5 plugin manager.

Namespace

Drupal\ckeditor5\Plugin

Code

public function getCKEditor5PluginConfig(EditorInterface $editor) : array {
  $definitions = $this
    ->getEnabledDefinitions($editor);

  // Allow plugin to modify config, such as loading dynamic values.
  $config = [];
  foreach ($definitions as $plugin_id => $definition) {
    $plugin = $this
      ->getPlugin($plugin_id, $editor);
    $config[$plugin_id] = $plugin
      ->getDynamicPluginConfig($definition
      ->getCKEditor5Config(), $editor);
  }

  // CKEditor 5 interprets wildcards from a "CKEditor 5 model element"
  // perspective, Drupal interprets wildcards from a "HTML element"
  // perspective. GHS is used to reconcile those two perspectives, to ensure
  // all expected HTML elements truly are supported.
  // The `ckeditor5_wildcardHtmlSupport` is automatically enabled when
  // necessary, and only when necessary.
  // @see \Drupal\ckeditor5\Plugin\CKEditor5PluginManager::getEnabledDefinitions()
  if (isset($definitions['ckeditor5_wildcardHtmlSupport'])) {
    $allowed_elements = new HTMLRestrictions($this
      ->getProvidedElements(array_keys($definitions), $editor, FALSE));

    // Compute the net new elements that the wildcard tags resolve into.
    $concrete_allowed_elements = $allowed_elements
      ->getConcreteSubset();
    $net_new_elements = $allowed_elements
      ->diff($concrete_allowed_elements);
    $config['ckeditor5_wildcardHtmlSupport'] = [
      'htmlSupport' => [
        'allow' => $net_new_elements
          ->toGeneralHtmlSupportConfig(),
      ],
    ];
  }
  return [
    'plugins' => $this
      ->mergeDefinitionValues('getCKEditor5Plugins', $definitions),
    'config' => NestedArray::mergeDeepArray($config),
  ];
}