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
- Create a link using a Drupal text format that has Editor Advanced Link options enabled.
- Now click on the created link (do not select all link text, just click on it!)
- Click the "Pencil" icons to edit the link
- Delete the existing displayed text in the link interface and enter replacement text
- Click "Update"
- 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
| Comment | File | Size | Author |
|---|---|---|---|
| #45 | editor_advanced_link-3534699-after.png | 72.18 KB | vladimiraus |
| #45 | editor_advanced_link-3534699-before.png | 104.67 KB | vladimiraus |
| #32 | editor_advanced_link_ckeditorv45-2.3.2.patch | 558.57 KB | mark_fullmer |
| #27 | editor-advanced-link-duplicate-links.mp4 | 159.63 KB | mark_fullmer |
| #23 | 3534699-23.patch | 202.92 KB | weseze |
Issue fork editor_advanced_link-3534699
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
Comment #4
jannakha commentedthis also fixes:
https://www.drupal.org/project/editor_advanced_link/issues/3519379
https://www.drupal.org/project/editor_advanced_link/issues/3534044
https://www.drupal.org/project/editor_advanced_link/issues/3391226
Comment #5
jannakha commented@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.
Comment #6
jannakha commentedComment #7
styx1983 commentedThe 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.
Comment #8
marc.groth commentedJust 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
Comment #9
tommasorandazzoConfirming 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
Comment #10
jcandan commentedConfirmed 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 buttarget="_blank"have been shown working in 2.3.1.Image link attributes are still broken. See #3349389: Fix image/media link attributes being lost.
Comment #11
jcandan commentedGiven #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.
Comment #12
jannakha commented@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...)
Comment #13
marc.groth commentedFWIW: Issue #3534044: Adding "Open in new window" removes all other attributes is fixed by applying the latest patch in #3535479-18: CKEditor v45: Compatibility with other plugins that modify link attributes
Comment #14
mrshowermanUsing 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:
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
⁠characters), and one for the part to the right of the cursor.When the link dialog is closed, the 3 links are replaced with one link again.
@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)
Comment #15
jannakha commentedI 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.
Comment #16
mark_fullmerAn issue for this has been created in the Linkit issue queue at #3540235: [CKEditor v45] Editing Displayed text from collapsed selection generates multiple links
Comment #17
thefancywizard commentedPatch 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.
Comment #18
thefancywizard commentedComment #19
jannakha commented@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!
Comment #20
mark_fullmerQuoting an issue from comment #14 that still is present in with the current changes:
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.
Comment #22
mark_fullmerOkay, 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
Comment #23
weseze commentedCan 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.
Comment #24
duaelfr#3534704: Fix CI issues has been shipped and released.
Let's move this forward!
Comment #25
mark_fullmerComment #26
mark_fullmerComment #27
mark_fullmerOkay, 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:
Comment #30
mark_fullmerChanging 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.
Comment #31
ammaletu commentedThank 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?
Comment #32
mark_fullmerSure, uploaded here: https://www.drupal.org/files/issues/2025-10-21/editor_advanced_link_cked...
Comment #33
ammaletu commentedThanks 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?!
Comment #34
inregards2plutoCurrently 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.
Comment #35
mark_fullmerThanks 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?
Comment #36
jannakha commentedI 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
Comment #37
jannakha commented@mark_fullmer why not create a MR out of #32?
Comment #40
jannakha commentedPlease 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)
Comment #41
inregards2plutoJust 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.
Comment #42
jannakha commentedThanks 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?
Comment #43
mark_fullmerUpon 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...
Comment #44
mark_fullmerOkay, 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.
Comment #45
vladimirausTested. See results before and after.
Before
After
Comment #46
inregards2plutoTested 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!
Comment #47
vladimirausThank you for contributions. 🎂
Merged and released. 🎁