Supported attribute(s) not showing in CKEditor 5 Source Editing plugin error message

Created on 6 May 2024, about 2 months ago
Updated 20 May 2024, about 1 month ago

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

  1. Login in as an admin user.
  2. Create a text format using CKEditor 5 with Source editing plugin and Text alignment plugin.
  3. In the 'Manually editable HTML tags' text box, add the following tags and attributes.
    <p class="text-align-center">
    
  4. Save the text format without any changes.
  5. 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

User interface changes

Before:

After:

API changes

TBD

Data model changes

TBD

Release notes snippet

TBD

🐛 Bug report
Status

Needs review

Version

11.0 🔥

Component
CKEditor 5 

Last updated about 4 hours ago

Created by

🇦🇺Australia Mingsong 🇦🇺

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.69.0 2024