0

This seems like it should be fairly simple, but I'm having trouble getting off the ground.

I have a content type "Document". This content type has a field of type File, which allows for uploading PDF's. This content type also has a title, such as "My User Manual".

I want to create a simple CKEditor plugin, similar to LinkIt that will allow a content editor to highlight a piece of text, click a button in CKEditor, search for and select Document content types.

The result will be that the highlighted text will be wrapped in an anchor tag with an href to the file (which comes from the Document > File field).

I know there are modules link IMCE which I can use to link to a file in the sites files, but I'm trying to simplify this a bit, as well as maintain only one file(s). I have also tried Entity Embed, unfortunately, this module embeds content, and doesn't necessarily allow for inline linking.

Thank you in advance for any insight you can provide.

1

There's an option, under "Url Substitution" for linkit Media matchers that allows exactly this, but for Media entities. It should be fairly straightforward to create a new plugin using Drupal\linkit\Plugin\Linkit\Substitution\Media as a reference. (You should just have to update the plugin definition annotation as well as the getUrl() and isApplicable() methods. Then you can exclude your Document content type from any previous linkit matcher and add a new linkit matcher to your profile that uses your new plugin for Url Substitution type to link to Documents.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.