Link attributes don't save

Created on 21 March 2023, over 1 year ago
Updated 13 June 2024, 9 days ago

Problem/Motivation

When I try to add attribute on the link of an image, nothing is save.

I'm using Ckeditor5, Linkit 6.0 and Editor advanced link 2.1 on Drupal 9.5.3

Steps to reproduce

  1. Go to node/x/edit
  2. Add an image
  3. Add a link to the image
  4. Add attribute on this link
  5. Save the node
  6. Inspect the image, no target blank, no class
  7. <a href="LINK"><img src="/sites/default/files/*.jpeg" data-entity-uuid="66ab0ac5-9fb2-4e2a-8402-f4f2fcc89c3b" data-entity-type="file" alt="alt" width="275" height="183" loading="lazy"></a>
    

Does someone have find a way to correct this error ?

๐Ÿ› Bug report
Status

Active

Version

2.2

Component

Code

Created by

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

Comments & Activities

  • Issue created by @GasparM
  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine ArialBlack

    I have the same issue

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom oliveyrc Hampshire

    Having the same issue here, tried adding target="_blank" in source view and it gets stripped as well.

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany Lissy

    Same Issue here

  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland sir_squall

    Same issue there, I'm using IMCE and when we put an image in the body, and we try to add a link to it and put this in "open in a new window" option, it's not working

  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland sir_squall

    Does anyone know if this will be prioritized? It's having a significant impact on the end user. Not being able to open external links in new windows is quite annoying.

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany Lissy

    @sir_squall You are so right with "significant impact on the end user."
    My customer are not amused.

  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland sir_squall

    Yes, same on my side, my client don't understand why they cannot put external link on image and opening in an external window...

    I hope this issue will be solve soon.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States quicksketch

    I ran into this same issue while porting link handling to Backdrop CMS (see https://github.com/backdrop-contrib/ckeditor5/issues/54). We started with the editor_advanced_link CKEditor plugin and adapted it for modal dialogs. Normal link handling works fine, but as is the case here, it does not work to apply attributes to images.

    I'm investigating this in our own module, whatever solution we find I'll try to post back here.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States quicksketch

    It looks like for the most part, all attributes are already defined that editor_advanced_link needs, and they upcast and downcast fine. What's missing is that when setting or getting attributes for a link around an image, the attributes need to come from the image model, not the anchor. CKEditors LinkImage "absorbs" the wrapping <a> tag into the image model.

    Although this is not a comprehensive solution, in _addExtraAttributeOnLinkCommandExecute() something like this needs to be executed when link command is fired:

            // If there is an image within this link, apply the link attributes to
            // the image model's htmlLinkAttributes attribute.
            const imageUtils = editor.plugins.get('ImageUtils');
            const closestImage = imageUtils.getClosestSelectedImageElement(selection);
            if (closestImage) {
              const htmlLinkAttributes = { attributes: extraAttributeValues };
              writer.setAttribute('htmlLinkAttributes', htmlLinkAttributes, closestImage);
            }
    

    Note when setting htmlLinkAttributes the actual attribute names should be used (i.e. rel or id) rather than the model names (linkRel or linkId).

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada FranckyLFS Montreal

    Like #4, I don't know why and I can't explain it, but on some image positions it doesn't work for me either.

    I'm using CKEditor 5, Linkit 6.0 and Editor Advanced Link 2.2.4 on Drupal 9.5.11.

  • Same problem here Ckeditor 5, linkit 6, EAL 2.2.4 and drupal 10.2.2
    title and target attributes are removed, only href works in my case.

  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland sir_squall

    The issue is still there, but no one is able to help us on that, unfortunately.

  • ๐Ÿ‡ฒ๐Ÿ‡ถMartinique wildhostile

    Hi,
    target='_blank' works when using text-align to center the image.
    As a workaround, you can choose aligned for the image position and use text-align (as if you were aligning a paragraph text) to align the image.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium jonas139

    Also looking into this issue and was trying the workaround from #14 which worked but it's not necessary to add a text-alignment. I've noticed that when you wrap your image in a

    element, the target attribute is also working. Still looking for a better solution but maybe this will also help some people.

  • I have same issu with Drupal 10.2.4 and Editor Advanced link 2.2.4.
    No attributes are saved.
    I tried adding them manually via edit source code when I save the attributes are deleted

  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand Gold 20 minutes in the future

    I'll add my +1 to this issue. I have just stripped out all but the bare minimum to get this to appear on the bar and after ensuring that it is configured to allow all the fields it offers none make it into the HTML. Not in the Source in the editor or on the rendered page.

    My scenario has this happening on the addition to the Editor File upload โ†’ field. Adding values does not survive submission of the modal. The HTML has these extra fields striped so when editing the field again they're still empty.

    I stood up a SimplyTest.me instance using the Standard profile with just editor_advanced_link and the standard Link field in CKEditor had the new fields and they worked as expected.

    I added Editor File upload module, enabled it, added that button to the bar, and tested. The error described was present there also.

    This is feeling slightly different to the scenario of the inital report, but it feels close enough that they're likely the same issue.

  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand Gold 20 minutes in the future

    I'm still seeing this on 2.2.4.

    Also, I'm seeing this on any file, not just images.

  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand Gold 20 minutes in the future

    Further discovery:

    I'm kinda old school and things like webpack are a hurdle for me. With the assistance of a co-worker though I got this to a point where I could debug things. Just in case others are in my position...

    I checked out the module from git and edited webpack.config.js. In const bc = {} I added devtools: 'inline-source-map' and commented out the whole optimization: {} section. From the module dir, running npm i preped things and npm run watch would rebuild the JS that's actually used as the source files are edited.

    Iโ€™ve now got it to the point where the JS is clear and breakpoints are working. Iโ€™ve added a breakpoint to the start of literally every function in the JS in this module. Loading the page shows breakpoints are working. I also have XDebug running and submitting the form does trigger a callback to Drupal and I can see it track though _editor_advanced_link_attributes_validate() in editor_advanced_link.module. What Iโ€™m not seeing is any JS being triggered in the module upon return to CKEditor.

    This doesnโ€™t feel right. It would seem to me that something in the EAL JS should be pulling details from the response and populating the link that is added in the body of CKEditor.

    Anyway, this is where I got to. I'll continue to poke at this when I can, but if anyone knows CKEditor 5 plugins and knows how that trigger should happen please contribute to the discussion. I'm happy to do the work, I just need pointers.

  • I have same issu with Drupal 10.2.5 and Editor Advanced link 2.2.4.
    No attributes are saved.

  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand Gold 20 minutes in the future

    @krish1505, nuts. I was just looking at the changelog and wondering if one of the CKE updates may have resolved this. Cheers for being on top of that.

  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand Gold 20 minutes in the future

    Hey all,

    My issue with this has been around using this module with the paired editor_file module.

    It is looking like this issue is very similar and may have a working patch. It isn't working for me, but others are claiming it works for them.

    https://www.drupal.org/project/editor_advanced_link/issues/3416599 โœจ Edit_Advanced_Link+Editor_file: conflicting field attributes RTBC

    Can people head that way and test the patch there?

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly nicoschi

    Hi there, I'm dealing with the same issue when wrapping a "drupal-media" in CKEditor using "Embed media". I'm not using editor_file, anyway i tried the patch and it doen't work form me too. What I can say in addition is that the editor advanced link doesn't keep in place any tag attribute except the target one which all of you is complaining not working

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States tim.tripp

    I'm interested in this as well as another CKEditor 5 plugin developer, it was brought to my attention by @SnowCoder that the advanced link attributes are getting stripped from my Icon widgets as well as Drupal Media widgets. Drupal Media seems better than Icon at preserving the target="_blank" specifically but always strips the other attributes like title and aria-label just like Icon.

Production build 0.69.0 2024