function CKEditor5PluginDefinition::validateCKEditor5Aspects

Same name and namespace in other branches
  1. 9 core/modules/ckeditor5/src/Plugin/CKEditor5PluginDefinition.php \Drupal\ckeditor5\Plugin\CKEditor5PluginDefinition::validateCKEditor5Aspects()
  2. 11.x core/modules/ckeditor5/src/Plugin/CKEditor5PluginDefinition.php \Drupal\ckeditor5\Plugin\CKEditor5PluginDefinition::validateCKEditor5Aspects()

Validates the CKEditor 5 aspects of the CKEditor 5 plugin definition.

@internal

Parameters

string $id: The plugin ID, for use in exception messages.

array $definition: The plugin definition to validate.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

See also

\Drupal\ckeditor5\Plugin\CKEditor5PluginManager::processDefinition()

File

core/modules/ckeditor5/src/Plugin/CKEditor5PluginDefinition.php, line 84

Class

CKEditor5PluginDefinition
Provides an implementation of a CKEditor 5 plugin definition.

Namespace

Drupal\ckeditor5\Plugin

Code

public static function validateCKEditor5Aspects(string $id, array $definition) : void {
    if (!isset($definition['ckeditor5'])) {
        throw new InvalidPluginDefinitionException($id, sprintf('The "%s" CKEditor 5 plugin definition must contain a "ckeditor5" key.', $id));
    }
    if (!isset($definition['ckeditor5']['plugins'])) {
        throw new InvalidPluginDefinitionException($id, sprintf('The "%s" CKEditor 5 plugin definition must contain a "ckeditor5.plugins" key.', $id));
    }
    // Automatic link decorators make sense in CKEditor 5, where the generated
    // HTML must be assumed to be served as-is. But it does not make sense in
    // in Drupal, where we prefer not storing (hardcoding) such decisions in the
    // database. Drupal instead filters it on output, using the filter system.
    if (isset($definition['ckeditor5']['config']['link'])) {
        // @see https://ckeditor.com/docs/ckeditor5/latest/api/module_link_link-LinkDecoratorAutomaticDefinition.html
        if (isset($definition['ckeditor5']['config']['link']['decorators']) && is_array($definition['ckeditor5']['config']['link']['decorators'])) {
            foreach ($definition['ckeditor5']['config']['link']['decorators'] as $decorator) {
                if ($decorator['mode'] === 'automatic') {
                    throw new InvalidPluginDefinitionException($id, sprintf('The "%s" CKEditor 5 plugin definition specifies an automatic decorator, this is not supported. Use the Drupal filter system instead.', $id));
                }
            }
        }
        // CKEditor 5 offers one preconfigured automatic link decorator under a
        // special config flag.
        // @see https://ckeditor.com/docs/ckeditor5/latest/api/module_link_link-LinkConfig.html#member-addTargetToExternalLinks
        if (isset($definition['ckeditor5']['config']['link']['addTargetToExternalLinks']) && $definition['ckeditor5']['config']['link']['addTargetToExternalLinks']) {
            throw new InvalidPluginDefinitionException($id, sprintf('The "%s" CKEditor 5 plugin definition specifies an automatic decorator, this is not supported. Use the Drupal filter system instead.', $id));
        }
    }
}

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