Score:1

Modify text for inserted link with CKEditor Linkit plugin

za flag

I would like to modify text that is being converted to a link within CKEditor, using the Linkit plugin. Eg. When linking to a Media Document, append the file type and size.

I am using hook_form_editor_link_dialog_alter in order to modify the dialog form and capture and populate additional attributes on the resulting a element. But there does not appear to be a field for modifying the text.

I tried to set up an event listener in javascript, but am not sure to what or how to attach a listener to CKEDITOR events. Is it possible to listen on a plugin's execution?

Drupal 9.5.9, CKEditor 4, Linkit 6-rc1

cn flag
The 'flow' for this (or at least one that definitely works), is to add something like `$form['attributes']['data-foo']` in the hook you mentioned; that in turn gets added to the link, `<a data-foo="...">`, and then you create a custom filter plugin which looks for that data attribute in the DOM and adds to or modifies the HTML based on the attribute values. If you want to manipulate the HTML in the editor at edit time, I'm pretty sure you need to create a new CKEditor plugin
za flag
I was hoping to avoid creating an entire plugin, since Linkit was doing 99% of the work and CK4 is deprecated (moving to D10 shortly). I am already adding the attribute, so would like to just 'hook' into the insertion done by Linkit to change the text.
cn flag
It’s not done by Linkit, it’s done by a plug-in in Drupal core, which Linkit piggy backs off (and which doesn’t raise any JS events as far as I know). Plug-ins in CKE4 we’re difficult to extend, that’s why I’m assuming you’d need to make a new one, not because the functionality doesn’t already exist
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.