private static function CKEditor5PluginDefinition::validateCKEditor5Aspects in Drupal 10
Validates the CKEditor 5 aspects of the CKEditor 5 plugin definition.
Parameters
string $id: The plugin ID, for use in exception messages.
array $definition: The plugin definition to validate.
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
1 call to CKEditor5PluginDefinition::validateCKEditor5Aspects()
- CKEditor5PluginDefinition::__construct in core/
modules/ ckeditor5/ src/ Plugin/ CKEditor5PluginDefinition.php - CKEditor5PluginDefinition constructor.
File
- core/
modules/ ckeditor5/ src/ Plugin/ CKEditor5PluginDefinition.php, line 85
Class
- CKEditor5PluginDefinition
- Provides an implementation of a CKEditor 5 plugin definition.
Namespace
Drupal\ckeditor5\PluginCode
private 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));
}
}
}