Problem/Motivation

Drupal 10.5 / 11.2 updated to CKEditor version 45, which introduced significant changes to the LinkUI API. See https://ckeditor.com/docs/ckeditor5/latest/updating/guides/update-to-45.... . Among these changes, the UI now has a "Displayed Text" input for editing the text associated with this link. Additionally, link attributes are stored in a new way.

As a result of these changes Editor Advanced Link has two significant bugs that need to be addressed.

Bug 1: When Editor Advanced Link is used with other things that modify link attributes (e.g., the Drupal core Styles Dropdown, the Linkit Contrib module), it will now overwrite those other attributes because CKEditor v45's attribute storage has changed.

Bug 2: When a user selects an existing link and tries to update the displayed text (new ability in CKEditor v45), saving the updated link results in multiple links being generated -- a significant problem for content! In the CKEditor terminology, the problem is specific to the scenario where attributes are being updated when the "selection" is "collapsed" (i.e., the element was selected by clicking within, rather than highlighting the entire element). Video demonstrating problem using Drupal 11.2 and Editor Advanced Link, nothing else: https://www.drupal.org/files/issues/2025-10-09/editor-advanced-link-dupl...

Steps to reproduce Bug 2

  1. Create a link using a Drupal text format that has Editor Advanced Link options enabled.
  2. Now click on the created link (do not select all link text, just click on it!)
  3. Click the "Pencil" icons to edit the link
  4. Delete the existing displayed text in the link interface and enter replacement text
  5. Click "Update"
  6. Inspecting the inserted text (or switching to "Source" mode) shows that multiple adjacent links are present when there should be one.

User interface changes

none

API changes

Create a new methodology for calculating the range when a link selection is collapsed and add a helper method to update the range if the Displayed Text data has changed.

Data model changes

none

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

jannakha created an issue. See original summary.

jannakha changed the visibility of the branch 3534699-refactor-custom-js to hidden.

jannakha’s picture

@DuaelFr
Hello from Australia! I'm working with @vladimiraus and I did a refactoring of JS files to be more inline with CKEditor5 45+ - would you like to collaborate on it? I'm on slack or here.

jannakha’s picture

Title: Refactor custom JS for CKEditor5 v45+ » Refactor plugin for CKEditor5 v45+
styx1983’s picture

The MR seems to fix all problems we are currently experiencing with the latest release 2.3.1 on Drupal 11.

Especially the "Uncaught CKEditorError: can't access property "_items", t._manualDecoratorSwitches is undefined" that prevented linkit from working properly seems to be fixed within this one.

marc.groth’s picture

Just to clarify... Issue #3534044 is still an issue. It's a bit confusing because the problem is listed as a known issue under 'Remaining tasks'... But then comment #4 says that the patch fixes it. The former is true. It is still an issue. I also added a comment to the aforementioned ticket

tommasorandazzo’s picture

Confirming that this fixes my issue with 2.3.1. It also seemed to fix the issue in #3534044 for me. Drupal core 11.2.2

jcandan’s picture

Confirmed text link attributes all persist as expected with MR !37 on 2.3.x with Drupal 11.2.2.

However, MR !37 breaks image link attributes which, according to #3349389-47: Fix image/media link attributes being lost, all but target="_blank" have been shown working in 2.3.1.

Image link attributes are still broken. See #3349389: Fix image/media link attributes being lost.

jcandan’s picture

Given #3349389: Fix image/media link attributes being lost bug affects both 2.2.x and 2.3.x,

And given the effort here to fix 2.3.x specifically for CKEditor 45+

Can we officially adopt the image/media link attributes bug within the scope of this issue?

This would allow us to laser focus on the issues as they exist differently in each minor version.

The question is, are we willing to change the scope of each, given the amount of work already attempted?

Give it a day or so, if no comments to the contrary, I may go in and update and clarify scopes for each.

jannakha’s picture

@jcandan I'll see if have some time next week to check how to handle link attrs on media (it's something to do with their upgrade in v44 and https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-lin...)

mrshowerman’s picture

Using the patch from MR37 together with Linkit 7.0.8, which added a similar change, I am experiencing some strange behavior.

I have a link like this:

<a href="/node/30" data-entity-type="node" data-entity-uuid="85f7822b-f889-4515-9e20-1addb7ef8e57" data-entity-substitution="canonical">FOOBAR</a>

When I click on it and edit an attribute (e.g. "Open in new window"), the link is temporarily split up into 3 links: one for the part to the left of the cursor, one invisible filler link (containing only 7 &NoBreak; characters), and one for the part to the right of the cursor.

<a class="ck-link_selected" href="/node/30" data-entity-type="node" data-entity-uuid="85f7822b-f889-4515-9e20-1addb7ef8e57" data-entity-substitution="canonical" target="_blank">FOO</a>
<a class="ck-link_selected" href="/node/30" target="_blank">⁠⁠⁠⁠⁠⁠⁠</a>
<a class="ck-link_selected" href="/node/30" data-entity-type="node" data-entity-uuid="85f7822b-f889-4515-9e20-1addb7ef8e57" data-entity-substitution="canonical" target="_blank">BAR</a>

When the link dialog is closed, the 3 links are replaced with one link again.

<a href="/node/30" data-entity-type="node" data-entity-uuid="85f7822b-f889-4515-9e20-1addb7ef8e57" data-entity-substitution="canonical" target="_blank">FOOBAR</a>

@jannakha, do you have any idea why this happens?

While it normally shouldn't be a problem for most users, it messes up the display for us, because we add an icon to the text through CSS to links that open a new window.
Thus, the text temporarily looks like this:

FOO ↗ ↗BAR ↗
(should be FOOBAR ↗, of course)

jannakha’s picture

StatusFileSize
new329.33 KB
new268.97 KB

I can confirm I can reproduce it (see screenshot).

@mrshowerman yeah, that's an issue of not going proper version for CKEditor 45+.

Reason for it: CKEditor 44 refactored links api (Drupal is using 45+) which is not compatible with current versions of editor_advanced_link, linkit and other modules as they are now.

linkit 7.0.8 is a bare min refactor to keep attributes of the link, it's not a proper refactor for CKEditor 45+

Fix (not really a fix, but an example of proper refactoring for CKEditor 45+):
- install linkit 7.0.7 and patch https://git.drupalcode.org/project/linkit/-/merge_requests/122.diff (hidden fork on https://www.drupal.org/project/linkit/issues/3535479) - that works (see screenshot).

Please re-open (or open a new bug) https://www.drupal.org/project/linkit/issues/3535479 and indicate to the maintainer that proper CKEditor 45+ refactoring is required.

mark_fullmer’s picture

Please re-open (or open a new bug) https://www.drupal.org/project/linkit/issues/3535479 and indicate to the maintainer that proper CKEditor 45+ refactoring is required.

An issue for this has been created in the Linkit issue queue at #3540235: [CKEditor v45] Editing Displayed text from collapsed selection generates multiple links

thefancywizard’s picture

StatusFileSize
new618.25 KB

Patch created from the current state merge request diff. - Edit - this version of the patch had an encoding issue with an emoji. If you need the patch please use the one in comment #18.

thefancywizard’s picture

StatusFileSize
new617.88 KB
jannakha’s picture

@thefancywizard can you create MR with patch #18? you can get push access to existing fork and MR37 will include your changes
It will really help with reviewing/testing process

thank you!

mark_fullmer’s picture

Quoting an issue from comment #14 that still is present in with the current changes:

When I click on it and edit an attribute (e.g. "Open in new window"), the link is temporarily split up into 3 links: one for the part to the left of the cursor, one invisible filler link (containing only 7 &NoBreak; characters), and one for the part to the right of the cursor.

I'm investigating a similar regression in the Linkit module #3540235: [CKEditor v45] Editing Displayed text from collapsed selection generates multiple links and have isolated the problem to how the code determines the "range" for applying attributes, specifically when the link is selected by "clicking"; in CKEditor terminology this is referred as a "collapsed selection."

In Editor Advanced Link, the problematic code is here: https://git.drupalcode.org/project/editor_advanced_link/-/blob/2.2.x/js/... . When the selection is not collapsed (i.e., the link was selected by highlighting the entire link), the "range" is calculated correctly.

I haven't yet figured out the appropriate refactor for Linkit, but wanted to provide a heads up for this gnarly problem to others working on this refactor.

mark_fullmer’s picture

Okay, I was able to figure out the issue described in #20!

The approach in the existing merge request, as well as recent patches, include a large number of naming changes that are not required for providing compatibility with CKEditor version 45. To simplify the maintainers' review process, and to expedite the hopeful fixing of this issue, I've created a new merge request only with the changes required for compability with CKEditor v45. I did not update the automated tests since that work is happening in #3534704: Fix CI issues.

The merge request https://git.drupalcode.org/project/editor_advanced_link/-/merge_requests/43 accomplishes the following specific goals:

- [ ] Relocates where the Editor Advanced Link attributes are stored and passed (now in a dedicated key in args[1]). This is important so that Editor Advanced Link doesn't overwrite other arguments coming from other providers, and was the thing originally identified in this issue as a problem.
- [ ] Relocates the "title" attribute form input into within the "Advanced" group.
- [ ] Fixes the problem described in #14 and #20, where clicking a link and then editing it results in multiple links being created in the markup

weseze’s picture

StatusFileSize
new202.92 KB

Can confirm this issue on Drupal 11.2.4 and confirmed that the MR fixes it.
Also adding a static patch based in the MR, for use in composer patches workflow.

duaelfr’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

#3534704: Fix CI issues has been shipped and released.
Let's move this forward!

mark_fullmer’s picture

Title: Refactor plugin for CKEditor5 v45+ » [CKEditor5 v45+] Attributes can overwrite other attributes and editing displayed text from collapsed selection generates multiple links
Issue summary: View changes
Priority: Normal » Major
Issue tags: -Needs reroll
mark_fullmer’s picture

Issue summary: View changes
mark_fullmer’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new159.63 KB

Okay, I've updated the merge request to incorporate the changes from the latest 2.3.x. Tests are green! Setting to "Needs review." Since this is a complicated issue history, to summarize, the things to review are:

  1. [ ] Bugfix: Clicking a link, updating the displayed text, then saving no longer results in multiple links being created in the markup (see full Steps to Reproduce in issue description, above; video demonstrating problem at https://www.drupal.org/files/issues/2025-10-09/editor-advanced-link-dupl...
  2. [ ] Bugfig: Store Editor Advanced Link attributes in a dedicated key in args[1]. This is important so that Editor Advanced Link doesn't overwrite other arguments coming from other providers, and was the thing originally identified in this issue as a problem: https://www.drupal.org/project/editor_advanced_link/issues/3534044#comme... . See also problem described in #3534618: Initialize advanced attributes (`id`, `rel`) on link dialog open for new links in CKEditor 5
  3. [ ] The "Title" attribute was erroneously omitted from the "Advanced" grouping in the UI. With CKEditor version 45 now having a "Displayed Text" field present, to reduce confusion, the "Title" attribute should be moved into the "Advanced" grouping

mark_fullmer changed the visibility of the branch 3534699-minimal to hidden.

mark_fullmer changed the visibility of the branch 3534699-minimal to active.

mark_fullmer’s picture

Priority: Major » Critical

Changing the priority from "Major" to "Critical," since Bug No. 2 in the issue description represents an easily reproducible scenario that results in data corruption that cannot be reversed without manual intervention.

ammaletu’s picture

Thank you, Mark, for working on this! I tested the MR 43 as it was 20 days ago, with module version 2.3.1 and Drupal 10.5.3. Everything worked.

Now I upgraded to Drupal 10.5.4 and module version 2.3.2. The old patch did not apply anymore, so I used the current version from MR 43. This did not apply as well. I get *.rej files for package-lock.json, editoradvancedlinkediting.js and editorAdvancedLink.js. Any chance we can get a patch file that applies to version 2.3.2?

mark_fullmer’s picture

StatusFileSize
new558.57 KB

Any chance we can get a patch file that applies to version 2.3.2

Sure, uploaded here: https://www.drupal.org/files/issues/2025-10-21/editor_advanced_link_cked...

ammaletu’s picture

Thanks for the patch file, Mark! The patch from #32 applies with Drupal 10.5.4 and Editor Advanced Link 2.3.2. I followed the steps from the issue description and found no problems with split links anymore.

Maybe some of the other commenters from above can test this with Drupal 11 and then this is ready for a new module version?!

inregards2pluto’s picture

Currently using Drupal 11.2.5 with Editor Advanced Link v2.3.2, Linkit v7.0.10, and CKEditor Plugin Pack v1.4.1 with the Link Attribute plugin enabled.

I can confirm the patch from #32 fixes the split link bug. However, attributes are still getting lost and the edit link dialog is overwriting advanced attribute fields. E.g. if I change the title field in link #1, press the "Update" button, and then edit link #2, it will show the title field I wrote for link #1.

mark_fullmer’s picture

Thanks for reporting the issues in #34!

I am able to establish that on Drupal 10.4.8 (i.e., CKEditor < v45) with Editor Advanced Link 2.2.6, the problem described of populating link attribute values in an new link from an old link is also present. Therefore I conclude it shouldn't be considered in the scope of this issue.

I think we need to define that in a separate issue (potentially redefining #3540304: Title and all other fields' values are not cleaned up when creating multiple links to include the larger scope described here), and provide specific steps to reproduce. (For me, it seemed like I needed some of the fields in the first link to be blank for the values to populate the second link.)

Separately, in my testing on Drupal 11.2 with this branch, I was unable to reproduce a scenario where the attributes get lost. Could you provide more specific steps to reproduce, ideally with just Editor Advanced Link (not Linkit or CKEditor Plugin Pack v1.4.1 with the Link Attribute), to help determine whether this is related to the CKEditor v45+ update or not?

jannakha’s picture

Status: Needs review » Needs work

I have tested MR#43 and #32 on D11.2.

Unfortunately, all issues are still there:
- link is splitting
- values in advanced tab (and display text) appear/disappear randomly
- multiple links mix advanced values (even without clicking update)
- tab order of the text fields is not correct and advanced tab is reachable by keyboard

here's testing: https://youtu.be/d80reijHsD0 and https://youtu.be/maspn44C1nU

Perhaps, editor_advanced_link does need a proper refactoring for CKEditor v45+ not just a patching

jannakha’s picture

@mark_fullmer why not create a MR out of #32?

jannakha changed the visibility of the branch 3534699-minimal to hidden.

jannakha changed the visibility of the branch 2.3.x to hidden.

jannakha’s picture

Status: Needs work » Needs review

Please review MR 37, it also resolves these issues:
#3519379: Fix keyboard accessibility of advanced attribute fields
#3349389: Fix image/media link attributes being lost

I've tested MR 37 on D11 with multiple links in same CKEditor5 window, opening/closing/editing/editing image as a link - try to break it!
let me know if there are any errors.

(haven't tested it with linkit yet)

inregards2pluto’s picture

Just tested MR37 using the same setup I described in #34.

Can confirm that MR37 from #38 fixes the issue with attributes being lost that I described in #34, but does NOT fix the multiple link issues.

I'm going to see if the fixes from MR37 can be easily combined with the patch from #32. Crossing my fingers that the fact they separately address different issues means that combined they'll address all the issues in this ticket. Will report back how it goes.

jannakha’s picture

Thanks for testing @inregards2pluto

MR 37 contains code from #32 patch with a fix.

Do you have Linkit enabled when you tested?
Is it possible to record a video of how link splitting appears?

mark_fullmer’s picture

Can confirm that MR37 from #38 fixes the issue with attributes being lost that I described in #34, but does NOT fix the multiple link issues.

Do you have Linkit enabled when you tested?
Is it possible to record a video of how link splitting appears?

Upon initial testing, I am able to reproduce the link splitting problem when Linkit is enabled (using the MR in #3555749: Data attributes of a new link are always applied to the FIRST link), but am not able to reproduce the link splitting problem when only Editor Advanced Link is being used. See video showing the problem with Linkit enabled: https://www.youtube.com/watch?v=K7HvqUJAd0U . I am also able to reference comment #20, above, which established that link splitting *was* previously an issue in Editor Advanced Link when used on its own. Looking into the Linkit side of things now...

mark_fullmer’s picture

Okay, I made some updates to how Linkit handles the problem of finding the collapsed selection range . I've tested both this MR and the MR in #3555749: Data attributes of a new link are always applied to the FIRST link in conjunction, and think what would be important for others to confirm not only that the MR for Editor Advanced Link works in isolation, but since many people use Linkit and Editor Advanced Link together, that testing the MR here plus the MR in #3555749: Data attributes of a new link are always applied to the FIRST link does not result in issues. What people should NOT do is test this MR with the latest release of Linkit or vice versa, since both modules have the same problem.

vladimiraus’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new104.67 KB
new72.18 KB

Tested. See results before and after.

Before

before

After

after

inregards2pluto’s picture

Tested this MR on Drupal 11.2.5 with Editor Advanced Link v2.3.2, Linkit v7.0.11 (which contains the MR fix referenced above), and CKEditor Plugin Pack v1.4.1 with the Link Attribute plugin enabled. Happy to report everything is working as expected :) Thank you to everyone who worked on this!

vladimiraus’s picture

Status: Reviewed & tested by the community » Fixed

Thank you for contributions. 🎂
Merged and released. 🎁

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.

Status: Fixed » Closed (fixed)

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