Make CKEditor be forgiving of enabling something that's already enabled

Created on 15 August 2024, 4 months ago
Updated 18 September 2024, 3 months ago

Problem/Motivation

CKEditor appears to be throwing an error for something that it could be forgiving of. Specifically, if I add a module that adds a tag that has already been added, it throws an error. I believe it could throw an informational message instead and not block adding the module, and just not duplicated the work that has already been done.

That is, if a given tag is added by both a CKEditor 5 toolbar plugin and the Manually Editable HTML Tags field, don't error, only warn. Otherwise, the wording needs to be improved. See also 🐛 Inconsistent use of language regarding plugins Active .

Steps to reproduce

1. Go to simplytest.me
2. Choose Drupal core 10.3.2 as the project
3. Expand Advanced
4. Add project CKEditor Accordion 2.1.0
5. Click Create
6. Log in
7. Manage > Configuration > Text Formats and Editors
8. On the row for Basic HTML, click Configure
9. Drag the accordion icon into the Active toolbar

Expected result: Drupal accepts my action. It does not add the duplicate tag. It might throw a warning or notice.

'The following tag(s) are already supported by enabled plugins and will not be re-added to the Source Editing "Manually editable HTML tags" field: accordion (<dl>).'

Actual result: Drupal gives the error

'The following tag(s) are already supported by enabled plugins and should not be added to the Source Editing "Manually editable HTML tags" field: accordion (<dl>).'

I note the instructions under Source Editing read:

A list of HTML tags that can be used while editing source. It is only necessary to add tags that are not already supported by other enabled plugins. For example, if "Bold" is enabled, it is not necessary to add the <strong> tag, but it may be necessary to add <dl><dt><dd> in a format that does not have a definition list plugin, but requires definition list markup

Specifically with regard to

It is only necessary

, that implies it is permitted but not necessary to add such tags. However, the current behavior is that it is forbidden to add such tags.

If this issue is not implemented, then that wording would best be changed to (updated Sept. 18, 2024):

This plugin adds a list of HTML tags that can be used while editing source. Remove or do not add tags that are supported by other enabled plugins. For example, if "Bold" is enabled in the toolbar, do not add the <strong> tag here. If another plugin throws an error because it requires a tag but does not supply it, you will need to add that tag here.

"Remove" is needed because the tag may already be there. In fact, the wording

It may be necessary to add <dl><dt><dd>

is confusing because those tags are already there by default, so why would I need to add them? This probably also needs to be wordsmithed, although I'm not sure how.

Proposed resolution

Don't error on listed tags that are also enabled by plugins.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Feature request
Status

Active

Version

11.0 🔥

Component
CKEditor 5 

Last updated about 4 hours ago

Created by

🇺🇸United States charles belov San Francisco, CA, US

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

Comments & Activities

  • Issue created by @charles belov
  • 🇺🇸United States charles belov San Francisco, CA, US
  • 🇺🇸United States charles belov San Francisco, CA, US
  • 🇺🇸United States charles belov San Francisco, CA, US
  • 🇺🇸United States charles belov San Francisco, CA, US
  • 🇺🇸United States charles belov San Francisco, CA, US
  • 🇺🇸United States charles belov San Francisco, CA, US
  • 🇮🇳India annmarysruthy

    Current implementation ensures that HTML tags that are already supported by CKEditor 5 plugins are not redundantly added to the Source Editing. In core/modules/ckeditor5/src/Plugin/Validation/Constraint/SourceEditingRedundantTagsConstraintValidator.php, The code for this implementation is added and it ensures that tags already enabled by plugins are not added again and raises an error.

    I believe rephrasing the helptext would be better in this case. We can rephrase it to :

    "A list of HTML tags that can be used while editing source. Remove or do not add tags that are already supported by enabled plugins. For example, if "Bold" is enabled, do not add the tag. It may be necessary to add

  • 🇺🇸United States charles belov San Francisco, CA, US

    I'm not sure why it would be harmful if something has been specified twice to only do it once. That said, I guess if one removes something, then one would expect it to go away, which wouldn't happen if it were specified twice.

    Then I would suggest the following wording for Source editing:

    This plugin adds a list of HTML tags that can be used while editing source. Remove or do not add tags that are already supported by other enabled plugins. For example, if "Bold" is enabled in the toolbar, do not add the tag. If another plugin requires a tag but does not supply it, you will need to add that tag here.

  • 🇺🇸United States charles belov San Francisco, CA, US
Production build 0.71.5 2024