Custom link data-attributes

Created on 3 February 2025, 3 months ago

Problem/motivation

I want to create a custom matcher plugin for a specific entity and bundle type that when used can return a link with additional data-attributes to trigger client side behaviors like trigger a modal.

I can't quite figure out what I need to modify in order to support this. I'd like to have links be abstract and have the same UI without the user having to enter their own attributes on a link.

✨ Feature request
Status

Active

Version

7.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States kevinquillen

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

Comments & Activities

  • Issue created by @kevinquillen
  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    Given that this feature explicitly does not want user interaction -- i.e., specific types of links should receive these data attributes consistently -- would an alternate, potentially simpler solution, be to create a text format filter for links in rich text fields, and/or to create a link formatter that extends Drupal core's formatter for link fields?

  • πŸ‡ΊπŸ‡ΈUnited States kevinquillen

    I thought I could get away with this by creating a link template for my custom entity and specifying that in the matcher. While that was working, I wanted the link element to also have additional attributes added automatically (because this specific entity match should open in a modal window) - i.e. let JS take over. Without requiring any additional action from the editor. I could not figure out how to modify the element before it was added into CKEditor to have that.

    I guess my only option because I am crunched for time is to add in https://www.drupal.org/project/editor_advanced_link β†’ and add a custom checkbox or two and work the rest from JS.

Production build 0.71.5 2024