Problem/Motivation

Three defects in how the module wires its CKEditor 5 plugin, found in a full configuration-matrix round on Drupal 11.4:

  1. Anchors are lost in editors that never enabled the Anchor button. hook_ckeditor5_plugin_info_alter() rewrites the Arbitrary HTML Support plugin definition globally, disallowing the id and name attributes on <a> site-wide. In an unrestricted format without the Anchor button, nothing else claims those attributes, so existing <a id="section-1"> and <a name="top"> are dropped from the model the moment the editor loads, and saving destroys them.
  2. The editor fails entirely when the Anchor button is placed without the Link button. The library's AnchorUI requires LinkEditing and LinkUI, so a toolbar with anchor and no link throws CKEditorError: plugincollection-soft-required and no editor attaches at all - the author gets a bare textarea.
  3. The elements list overclaims. <a target="">, <a rel=""> and <a class="ck-anchor"> are declared but the plugin never creates them (the library stopped writing ck-anchor in 2.0.5), so every restricted format that enables the button gets those attributes added to its allowed HTML for nothing.

Steps to reproduce

  1. Create an unrestricted text format with sourceEditing and no Anchor button; save a node containing <a id="keep-in-ghs">anchor target</a>; reopen it - the editor data reads <a>anchor target</a>.
  2. Create a format whose toolbar has the Anchor button and no Link button; open any node using it - the console shows plugincollection-soft-required and no editor attaches.

Proposed resolution

  • Move the General HTML Support disallow of the anchor attributes into the plugin's own ckeditor5.config.htmlSupport.disallow, so it only applies where the Anchor button is enabled, and drop the global alter with its legacy wrapper.
  • Load link.LinkEditing and link.LinkUI with the anchor plugin, so the editor attaches whatever the toolbar holds.
  • Trim the elements list to <a>, <a id=""> and <a name="">.
  • Rework the unit test to cover the plugin definition shape.

Remaining tasks

  • ✅ File an issue
  • ✅ Addition/Change/Update/Fix
  • ✅ Testing to ensure no regression
  • ✅ Automated unit/functional testing coverage
  • ➖ Developer Documentation support
  • ➖ User Guide Documentation support
  • ➖ UX/UI designer responsibilities
  • ➖ Accessibility and Readability
  • ❌ Reviewed by a human
  • ❌ Code review by maintainers
  • ✅ Full testing and approval
  • ✅ Credit contributors
  • ✅ Review with the product owner
  • ✅ Update Release Notes
  • ✅ Release

User interface changes

  • N/A

API changes

  • The hook_ckeditor5_plugin_info_alter() implementation is removed; the disallow moves into the plugin definition.

Data model changes

  • Restricted formats that re-save their editor settings lose the unused target, rel and ck-anchor entries from their allowed HTML.

Release notes snippet

  • Anchors are no longer stripped from editors that do not use the Anchor button, and the editor attaches when the Anchor button is placed without the Link button.
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

rajab natshah created an issue. See original summary.

rajab natshah’s picture

Status: Active » Needs review

  • rajab natshah committed 167beb86 on 3.0.x
    fix: #3619043 Scope the CKEditor 5 plugin wiring to the editors that use...
rajab natshah’s picture

Status: Needs review » Fixed
Issue tags: +anchor_link-3.0.5

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

rajab natshah’s picture

Issue summary: View changes

✅ Released anchor_link-3.0.5

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.