Opened 9 years ago

Closed 9 years ago

#13885 closed Task (fixed)

Make Image2 widget linking possible without a direct dependency of Link Plugin.

Reported by: Olek Nowodziński Owned by: Olek Nowodziński
Priority: Normal Milestone: CKEditor 4.5.5
Component: UI : Widgets Version:
Keywords: Drupal Cc: wim.leers@…, nate@…

Description

A followup of https://www.drupal.org/node/2510380.

Problem

At the moment, linking of Image2 widgets depends strictly on Link Plugin's CKEDITOR.plugins.link.(parse|get)LinkAttributes

Because of this hard dependency, when the Link plugin is not loaded, there's no way to enable Image2 widget linking with an external link parser/serialiser (like (parse|get)LinkAttributes).

Cake recipe

The idea is quite straightforward: let's provide the link parsing/serialisation API via static CKEDITOR.plugins.image2 namespace, which already exists.

A method like CKEDITOR.plugins.image2.getLinkAPI() could return CKEDITOR.plugins.link namespace. Or a custom object, if one decided to overwrite it:

CKEDITOR.plugins.image2.getLinkAPI = function() {
    return {
        getLinkAttributes: function () { custom implementation },
        parseLinkAttributes: function () { custom implementation }
    }
}

Profits:

  1. Re–enable linking when Link plugin is not loaded.
  2. Allow a custom parsers/serialisers, which could be much simpler than default CKEDITOR.plugins.link.(parse|get)LinkAttributes implementations.

Change History (14)

comment:1 Changed 9 years ago by Olek Nowodziński

Owner: set to Olek Nowodziński
Status: newassigned

comment:2 Changed 9 years ago by Marek Lewandowski

cc

comment:3 Changed 9 years ago by Wim Leers

Cc: wim.leers@… added
Keywords: Drupal added

comment:4 Changed 9 years ago by Nathan Haug

Cc: nate@… added

comment:5 Changed 9 years ago by Olek Nowodziński

A prototype pushed to branch:t/13885.

comment:6 Changed 9 years ago by Wim Leers

@a.nowodzinski pinged me. I tested this, and it works splendidly.

Full review plus how Drupal would use this API at https://www.drupal.org/node/2510380#comment-10522410.

Text from there quoted here:

Good news! @oleq notified me that he has a proposed solution ready for testing at http://dev.ckeditor.com/ticket/13885#comment:5. I worked on updating the above patch to use the new API that his patch adds. And it indeed allows us to simplify the code here, *and* not pretend the CKEditor <code>link</code> plugin is present.

Note this is a future interdiff, that we cannot use until we update to CKEditor 4.5.5 (see #2321583) and until that fix is actually <em>committed</em> to CKEditor 4.5.5.

So, hurray, this will become more maintainable with CKEditor 4.5.5!

comment:7 Changed 9 years ago by Wim Leers

Remember my rant in chat about how the link plugin's data model is full with legacy stuff that makes it very hard to understand and use?

Well, I'm afraid this API will actually have to explicitly document that. Because if it doesn't use the exact same data structure, then it won't work.

Except… I could actually "ignore" link's data model and just use my own, as long as getLinkAttributes() returns the expected data structure ({set: {…}, remove: {}…}). Because the only thing that "actually" needs to be able to deal with parseLinkAttributes()'s return value, is getLinkAttributes(), right?

comment:8 Changed 9 years ago by Olek Nowodziński

@Wim: If you decide to use a custom Link dialog then yes, you can use whatever parseLinkAttributes() (getLinkAttributesParser()) implementation you want and you should be safe.

However you just need to keep the getLinkAttributes() API ({set: {…}, remove: {}…})) because it is used in CKEDITOR.plugins.image2.stateShifter to change the state of the widget.

I'll extend the documentation strings for both methods implemented in this ticket. I think that Link Plugin's legacy data format also deserves a few words of comment.

Last edited 9 years ago by Olek Nowodziński (previous) (diff)

comment:9 Changed 9 years ago by Wim Leers

Okay, thanks for confirming!

comment:10 Changed 9 years ago by Wim Leers

This will allow me to fix something in drupallink (Drupal's custom link plugin): the link plugin does "not" support just about any attribute you throw at it. The drupallink plugin does (needs to be able to).

Therefore, with the empowerment to have our own data structure in parseLinkAttributes(), we *can* support that without abusing link's data model.

See https://www.drupal.org/node/2608434#comment-10531568.

comment:11 Changed 9 years ago by Olek Nowodziński

Pushed an extensive documentation of getLinkAttributes(Parser|Getter)() and updated documentation of (parse|get)LinkAttributes() to branch:t/13885.

comment:12 Changed 9 years ago by Olek Nowodziński

Status: assignedreview

comment:13 Changed 9 years ago by Wim Leers

Thanks!

That looks perfect :)

comment:14 Changed 9 years ago by Marek Lewandowski

Resolution: fixed
Status: reviewclosed

Great! Merged to master with git:68b6b3bc.

Note: See TracTickets for help on using tickets.
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy