Problem/Motivation
When modifying "Manually editable HTML tags", there is an error message said
The following attribute(s) are already supported by enabled plugins and should not be added to the Source Editing "Manually editable HTML tags" field: .
The supported attribute's name is missing from the error message.
An expected error message is supported to provide the specific attribute name that is overlapped with plugins. Such as,
The following attribute(s) are already supported by enabled plugins and should not be added to the Source Editing "Manually editable HTML tags" field: Alignment (
<p class="text-align-center">
).
Steps to reproduce
- Login in as an admin user.
- Create a text format using CKEditor 5 with Source editing plugin and Text alignment plugin.
- In the 'Manually editable HTML tags' text box, add the following tags and attributes.
<p class="text-align-center">
- Save the text format without any changes.
- The error occured.
Proposed resolution
I believe this bug is caused by Drupal\ckeditor5\HTMLRestrictions::applyOperation() function.
https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/ckedi...
As the function description suggested, it is supposed to support wildcard within an element name. Therefore, the wildcard $text-container should be resolved into a concrete tag, so that the Alignment plugin should be chosen in the error message, for example. But actually the result is opposite.
Actually this function doesn't resolve the wildcard tag for some plugins, such as the Alignment plugin.
At line 1143, the comment inside the function resolveWildcards() suggest that,
https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/ckedi...
// Do not resolve to all tags supported by the wildcard tag, but only
// those which are explicitly supported. Because wildcard tags only
// allow declaring support for additional attributes and attribute
// values on already supported tags.
But the problem is that, the Alignment plugin only has a wildcard tag of '$text-container' , nothing else. So this logic won't work for this plugin or any other plugin which only has wildcard tags.
So if the logic is changed to
// Do not resolve to all tags supported by the wildcard tag, but only
// those which are explicitly supported by this set of restrictions
// or specified in the $supported_wildcard_tags array.
// Because wildcard tags only
// allow declaring support for additional attributes and attribute
// values on already supported tags.
if (isset($r->elements[$wildcard_tag]) || isset($supported_wildcard_tags[$wildcard_tag])) {
$naively_resolved_wildcard_elements[$wildcard_tag] = $tag_config;
}
It will work for all plugins.
Remaining tasks
PHPUnit test to reproduce this issue.Merge requests to fix this issue.
User interface changes
Before:
After:
API changes
TBD
Data model changes
TBD
Release notes snippet
TBD