Is it possible to automatically use the name of the target entity as the anchor text for a Linkit link?
For example, I know I want a link to the taxonomy term Entacmaea quadricolor, but I can only remember that it starts with "Ent". When I type "Ent" and I choose Entacmaea quadricolor from the Linkit drop-down menu, the anchor text for the link becomes /taxonomy/term/637. Instead I would like it to insert the words Entacmaea quadricolor and use them as the anchor text of the link, so I can avoid the extra steps of looking up the spelling of the term and modifying the anchor text.
To be clear, I am looking for this functionality when inserting a link via the "Link" button in CK Editor, without first selecting text to add a link to.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | label_as_text_filter-3014297-8.patch | 1023 bytes | kasey_mk |
Comments
Comment #2
anonCurrently this is not possible.
Comment #3
anonComment #4
nick hope commentedComment #5
nick hope commentedRe-opening after changing this to a feature request.
Comment #6
3cwebdev commentedAny update on this? Is it not possible to automatically populate the anchor text with the node title?
Comment #7
kasey_mk commentedIn linkit/src/Plugin/Filter/LinkitFilter.php adding this bit just after
$element->setAttribute('href', $url->getGeneratedUrl() . $query . $anchor);will replace the link text with the entity label if the link text matches the href attribute, but it only works on the page output, not in the WYSIWYG, and I don't know anything about translations:Comment #8
kasey_mk commentedIn case that much is helpful to anyone else, here's a patch to LinkitFIlter.php to replace the link text with the entity label if the link text matches the href attribute on page output.
Comment #9
nick hope commentedComment #10
nick hope commentedThank you @Kasey_MK. I am not sure if your patch was supposed to achieve exactly the feature I was hoping for, but unfortunately it does not. If I insert a link, without first selecting anchor text, and choose an item from the drop-down menu, the anchor text remains the URL, even after saving the article etc.. I was hoping for the anchor text to become the entity name (in my case a taxonomy term name).
To be clear, I am looking for this functionality when clicking the "Link" button in CK Editor, without first selecting text to add a link to. I have added that to the issue description.
Further, if it were only to work on page output, not in the WYSIWYG, I doubt I would enable it on a site due to the potential for editors to get unexpected results when content is published.
Comment #11
klidifia commentedI updated this issue with some code that will use the entity title (already obtained via Linkit) as the default link text for a brand new inserted link without a selection range: #3388565: Populate displayedText with entity title when left blank
Comment #12
nick hope commentedComment #13
nick hope commented