core/modules/ckeditor5/ckeditor5.ckeditor5.yml | 4 +++- .../src/Plugin/CKEditor5PluginDefinition.php | 28 +++++++++++----------- .../src/Plugin/CKEditor5PluginManager.php | 8 +++---- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/core/modules/ckeditor5/ckeditor5.ckeditor5.yml b/core/modules/ckeditor5/ckeditor5.ckeditor5.yml index a8195efcd0..05d0031750 100644 --- a/core/modules/ckeditor5/ckeditor5.ckeditor5.yml +++ b/core/modules/ckeditor5/ckeditor5.ckeditor5.yml @@ -117,7 +117,9 @@ ckeditor5_sourceEditing: class: \Drupal\ckeditor5\Plugin\CKEditor5Plugin\SourceEditing # This is the only CKEditor 5 plugin allowed to generate a superset of elements. # @see \Drupal\ckeditor5\Plugin\CKEditor5Plugin\SourceEditing::getElementsSubset() - elements: ['<*>'] + # @see \Drupal\ckeditor5\Plugin\CKEditor5PluginDefinition::validateDrupalAspects() + # @see \Drupal\ckeditor5\Plugin\CKEditor5PluginManager::getProvidedElements() + elements: [] library: core/ckeditor5.sourceEditing admin_library: ckeditor5/admin.sourceEditing toolbar_items: diff --git a/core/modules/ckeditor5/src/Plugin/CKEditor5PluginDefinition.php b/core/modules/ckeditor5/src/Plugin/CKEditor5PluginDefinition.php index 0222d76f2f..8e0aab0e68 100644 --- a/core/modules/ckeditor5/src/Plugin/CKEditor5PluginDefinition.php +++ b/core/modules/ckeditor5/src/Plugin/CKEditor5PluginDefinition.php @@ -122,25 +122,25 @@ private function validateDrupalAspects(string $id, array $definition): void { if (!isset($definition['drupal']['elements'])) { throw new InvalidPluginDefinitionException($id, sprintf('The "%s" CKEditor 5 plugin definition must contain a "drupal.elements" key.', $id)); } + // ckeditor5_sourceEditing is the edge case here: it is the only plugin that + // is allowed to return a superset. It's a special case because it is + // through configuring this particular plugin that additional HTML tags can + // be allowed. + // Even though its plugin definition says an empty list of tags is + // supported, this is a little lie to convey that this plugin is capable of + // supporting any HTML tag … but which ones are actually supported depends + // on the configuration. + // This also means that without any configuration, it does not support any + // HTML tags. + // @see \Drupal\ckeditor5\Plugin\CKEditor5PluginManager::getProvidedElements() + elseif ($definition['id'] === 'ckeditor5_sourceEditing') { + assert($definition['drupal']['elements'] === []); + } elseif ($definition['drupal']['elements'] !== FALSE && !(is_array($definition['drupal']['elements']) && !empty($definition['drupal']['elements']) && Inspector::assertAllStrings($definition['drupal']['elements']))) { throw new InvalidPluginDefinitionException($id, sprintf('The "%s" CKEditor 5 plugin definition has a "drupal.elements" value that is neither a list of HTML tags/attributes nor false.', $id)); } elseif (is_array($definition['drupal']['elements'])) { foreach ($definition['drupal']['elements'] as $index => $element) { - // ckeditor5_sourceEditing is the edge case here: it is the only plugin - // that is allowed to return a superset. It's a special case because it - // is through configuring this particular plugin that additional HTML - // tags can be allowed. - // Even though its plugin definition says '<*>' is supported, this is a - // little lie to convey that this plugin is capable of supporting any - // HTML tag … but which ones are actually supported depends on the - // configuration. - // This also means that without any configuration, it does not support - // any HTML tags. - // @see \Drupal\ckeditor5\Plugin\CKEditor5PluginManager::getProvidedElements() - if ($definition['id'] === 'ckeditor5_sourceEditing') { - continue; - } $parsed = HTMLRestrictions::fromString($element); if ($parsed->isEmpty()) { throw new InvalidPluginDefinitionException($id, sprintf('The "%s" CKEditor 5 plugin definition has a value at "drupal.elements.%d" that is not an HTML tag with optional attributes: "%s". Expected structure: "".', $id, $index, $element)); diff --git a/core/modules/ckeditor5/src/Plugin/CKEditor5PluginManager.php b/core/modules/ckeditor5/src/Plugin/CKEditor5PluginManager.php index 8f628a9035..19733426bd 100644 --- a/core/modules/ckeditor5/src/Plugin/CKEditor5PluginManager.php +++ b/core/modules/ckeditor5/src/Plugin/CKEditor5PluginManager.php @@ -318,10 +318,10 @@ public function getProvidedElements(array $plugin_ids = [], EditorInterface $edi // that is allowed to return a superset. It's a special case because it // is through configuring this particular plugin that additional HTML // tags can be allowed. - // Even though its plugin definition says '<*>' is supported, this is a - // little lie to convey that this plugin is capable of supporting any - // HTML tag … but which ones are actually supported depends on the - // configuration. + // Even though its plugin definition says an empty list of tags is + // supported, this is a little lie to convey that this plugin is capable + // of supporting any HTML tag … but which ones are actually supported + // depends on the configuration. // This also means that without any configuration, it does not support // any HTML tags. if ($id === 'ckeditor5_sourceEditing') {