The drupalimage plugin is making calls to drupallink.parseLinkAttributes & drupallink.getLinkAttributes without checking if drupallink is defined.

Comments

dylanf created an issue. See original summary.

dylanf’s picture

nod_’s picture

Status: Active » Needs review
Issue tags: +JavaScript
droplet’s picture

Issue tags: +Needs JS testing
Tyler_Marshall’s picture

Status: Needs review » Reviewed & tested by the community
Wim Leers’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests
  1. No tests yet!
  2. +++ b/core/modules/ckeditor/js/plugins/drupalimage/plugin.js
    @@ -285,12 +285,15 @@
       // Override image2's integration with the official CKEditor link plugin:
       // integrate with the drupallink plugin instead.
    -  CKEDITOR.plugins.image2.getLinkAttributesParser = function () {
    -    return CKEDITOR.plugins.drupallink.parseLinkAttributes;
    -  };
    -  CKEDITOR.plugins.image2.getLinkAttributesGetter = function () {
    -    return CKEDITOR.plugins.drupallink.getLinkAttributes;
    -  };
    +  if (CKEDITOR.plugins.drupallink) {
    +    CKEDITOR.plugins.image2.getLinkAttributesParser = function () {
    +      return CKEDITOR.plugins.drupallink.parseLinkAttributes;
    +    };
    +    CKEDITOR.plugins.image2.getLinkAttributesGetter = function () {
    +      return CKEDITOR.plugins.drupallink.getLinkAttributes;
    +    };
    +  }
    

    AFAICT this will cause it to integrate with the official CKEditor link plugin instead.

    What are the consequences of that?

  3. +++ b/core/modules/ckeditor/js/plugins/drupalimage/plugin.js
    @@ -285,12 +285,15 @@
    +
     
       /**
    

    Unwanted newline addition.

anthorn305’s picture

I was getting the following error when trying to link an image using the anchor_link module for linking in ckeditor.

Uncaught TypeError: Cannot read property 'getLinkAttributes' of undefined
    at Object.CKEDITOR.plugins.image2.getLinkAttributesGetter 

I ran the patch and it seems to have fixed the issue.

People are reporting this as an anchor_link issue, but it looks like it's really a Drupalimage issue.
#2848535: Unable to create link when wrapping img

Shawn DeArmond’s picture

Version: 8.2.x-dev » 8.3.x-dev

This needs to be 8.3.x now.

Dinesh18’s picture

Status: Needs work » Needs review
FileSize
1.07 KB

Re-rolled the patch #2 and fixed the unwanted new line addition.

Wim Leers’s picture

Status: Needs review » Needs work

Still needs work for #6.1 & #6.2.

Also, the anchor_link module is doing things that are absolutely not allowed. Opened #2888087: Unfortunately this module violates d.o guidelines and D8 guidelines — stop copy/pasting CKEditor plugin, roll our own for that.