0

A customer of mine, when they upload an image through the media browser, want to add an external URL to it. I tried adding the URL to the image field in the image type of media browser but I am not sure how to achieve this functionality.

screenshot

screenshot

1
  • A lazy/dirty hack way to do this is to add the link field to the node, and then hide the link from the display and use a theme template to make the media item into a link for that node type. Not pretty, but easy to do using only core functionality. Aug 11, 2022 at 15:52

1 Answer 1

0

1. How can I add a new field to a media item's form in the media browser?

Media have a 'Media library' Form Display mode - add the new field to this form display and it'll appear when adding the media item through the media library.

2. How can I render the media item with this new field?

Media have View modes, (configurable via the 'Manage display' tab of the media type). The first step is to configure a view mode to display your new field. Then configure your system to use that view mode when it renders the referenced media item.

If the media is added via an entity reference field on a node (or some other entity), configure the node to render the media with that view mode via the node's Manage Display screen.

If the media is uploaded through a WYSIWYG, configure the appropriate text format(s) to render media with the view mode you configured. This configuration is provided by the 'Embed media' filter and is unique per text format. (Text format configuration is found in the Administration menu at Configuration > Content authoring > Text formats and editors.)

p.s. To render the image linked, without custom code or templates, use the Linked Field module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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