When used in Drupal core 8.0.5 linkit doesn't link inline images properly.

In order to reproduce:

  • Create basic page
  • Upload an image through image CKEditor button
  • Select image and click on linkit button
  • Input URL
  • See that the link is inserted before the image like for example '/node/25' and then image itself not linked.

This is the source markup that is generated:
<p><a href="node/25">node/25</a><img alt="Link Test" data-entity-type="file" data-entity-uuid="618c1ef3-1199-44ea-8300-f136503903bf" height="278" src="/sites/default/files/inline-images/Giant-Panda.jpg" width="418" /></p>

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

amykhailova created an issue. See original summary.

amykhailova’s picture

I have tested it on the 8.x-4.1 and 8.x-4.x-dev versions of the module, both had the same problem for me.

star-szr’s picture

Version: 8.x-4.1 » 8.x-4.x-dev
Issue summary: View changes
Status: Active » Needs review
Issue tags: -images broken link
FileSize
3.74 KB

Confirmed, here's a patch which just pulls in code from the core Link plugin to handle images (makes the linkit CKEditor plugin more similar to the core link plugin).

This seems to work well and doesn't break normal linking as far as I can tell but needs more testing to confirm.

Note that you may need to clear browser cache to test this.

Wim Leers’s picture

Wow. All of this seemingly is only necessary because the LinkIt module reimplements all of the link dialog, instead of extending the existing one in Drupal 8.

Why doesn't this just alter EditorLinkDialog's form?

star-szr’s picture

Yeah I was kinda thinking to myself, why is this all repeated. Great point :)

anon’s picture

Extend the default would be perfect, But I cant figure out how to extend the allowedContent part of the default. Any ideas?

Wim Leers’s picture

Look at how the drupalimagecaption plugin extends the drupalimage plugin. It does exactly that IIRC :)

anon’s picture

drupalimage and drupalimagecaption are using the widgetDefinition event.

The drupallink plugin doesn't use that and I can't find any other way to alter the allowedContent.

Any thoughts?

Wim Leers’s picture

I wrote up my feedback in #2692831: Linkit 8.x-4.x flaws from the POV of the Text Editor/CKEditor APIs in Drupal 8 core.

For extending allowedContent for the drupallink CKEditor plugin (though I strongly doubt that is necessary here), you'd want to use afterInit.

anon’s picture

Version: 8.x-4.x-dev » 8.x-5.x-dev
Status: Needs review » Fixed

Fixed with #2692831.

Status: Fixed » Closed (fixed)

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

omnimon’s picture

Still happening im afraid, with the latest release or dev release.

anon’s picture

@omnimon: Na, I can not reproduce this. And it is very strange that this is still an issue for you as Linkit is now using the exact same js code as drupal core. Make sure to clear your cache.

thejimbirch’s picture

I just want to comment that upgrading to 8.x-5.x-dev fixed this for me.

heyehren’s picture

For me the links are still added in front of the image, even with running the latest dev version 8.x-5.0-beta5+4-dev on Drupal 8.3.7 and clearing the cache.

UPDATE: Ok, it is working with img tags for me as well now. What still doesn't work is to link images added by the entity embed module. But this is an issue related to their module. I have fixed it for now by using https://www.drupal.org/project/entity_embed_link

Tritof’s picture

Hi, I still have the problem Drupal 8.5.3 and linkit 8.4.3.

anonym-developer’s picture

Confirm #16, still the same issue with Drupal 8.5.6 and Linkit 8.4.3.

jasonflaherty’s picture

Confirming the same issue as noted above. Internal, Files and External links all insert before image.

gobnat’s picture

This is still happening for me.

Drupal version: 8.6.4

Any news if this is getting fixed?

alison’s picture

Still happening for me, too, core 8.7.6 + LinkIt 8.x-5.0-beta9 :(

embeau’s picture

I am still encountering this issue as well. Linkit version 8.x-4.3, Drupal version 8.6.7.

hkirsman’s picture

I'm getting with this patch:

 plugin.js?t=q7ne9r:250 Uncaught TypeError: Cannot read property 'getLinkAttributes' of undefined
    at Object.CKEDITOR.plugins.image2.getLinkAttributesGetter (plugin.js?t=q7ne9r:250)

Adding the patch from here https://www.drupal.org/project/drupal/issues/2855521 makes the js error go away but <a href="undefined">

I've now changed to 5.0-beta10 and it works (without the patches).

yojohnyo’s picture

I am encountering this problem on 8.x-5.0-beta10 Drupal version 8.8.4