Allow modules to alter EditorLinkDialog to specify link text

Created on 3 June 2016, over 8 years ago
Updated 18 May 2023, over 1 year ago

While working on a patch for Linkit I failed to set a custom attribute as link text without completely overriding the plugin.js of drupallink.

drupallink uses this code to create the link text: var text = new CKEDITOR.dom.text(returnValues.attributes.href.replace(/^mailto:/, ''), editor.document);
Do I have to override the complete plugin to use another attribute returned by the editor dialog?

Eventually the following code fragment would be an option (as a patch), but maybe there is a better way.

// Use link URL as text with a collapsed cursor.
if (range.collapsed) {
  // Shorten mailto URLs to just the email address.
  var text = new CKEDITOR.dom.text(returnValues.attributes.href.replace(/^mailto:/, ''), editor.document);
  if (editor.config.hasOwnProperty('drupalLink_attributeText') && returnValues.attributes.hasOwnProperty(editor.config.drupalLink_attributeText) && returnValues.attributes[editor.config.drupalLink_attributeText].length) {
    // Use custom attribute as link text.
    text = new CKEDITOR.dom.text(returnValues.attributes[editor.config.drupalLink_attributeText], editor.document);
  }
  range.insertNode(text);
  range.selectNodeContents(text);
}
Feature request
Status

Needs review

Version

1.0

Component

Code

Created by

🇩🇪Germany stborchert

Live updates comments and jobs are added and updated live.
  • Contributed project blocker

    It denotes an issue that prevents porting of a contributed project to the stable version of Drupal due to missing APIs, regressions, and so on.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024