6

I'm using Drupal 8.5. I have a content type with the in-core media module. I'm making a view for content syndication, and I need one of the columns to be the FDQN URI to the media resource-- i.e, not the rendered entity itself (which comes through as an img tag), but https://example.com/sites/default/files/media_image.jpg.

I've added the media field to my view, but I didn't find any Formatter, View Mode, or Rewrite Pattern that gives me the absolute URL to the resource. I can get the path to the media (e.g. https://example.com/media/1899), the entity_id (e.g. 1899), but no path to the file.

How can I render the path to the media image in my view?

2 Answers 2

13

The media field is an entity reference type field. You will need to add a relationship to the media entity. This should add the URI field in media entity to the view selections. You should then be able to select this (with the right reference relationship) and use the standard URL formatters.

1
  • 1
    Thanks for this @CG Monroe. It makes perfect sense. For anyone else tagging along, once you have created a relationship to the media entity for the type of node that you are referring to in your view, you can then select a media field with the relationship and use the URL formatter. Aug 7, 2020 at 0:55
5

The selected answer is perfect. I am adding screenshots since it is easier to understand for new users.

  1. Add the relationship to the media field (in my case field_banner_media)

enter image description here

  1. Click on "Add Fields" and select "Media" in category. Select the "Image" which is our media image field

enter image description here

  1. Select the relationship to field_banner_image(my case) and formatter to "URL to Image"

enter image description here

3
  • This answer worked like a charm in 9.4.1. Thanks for sharing :) Jul 5, 2022 at 1:58
  • Thank you for you answer, but i can't find Media category either in relationship or in add field paste.pics/f8812ffe537338e178788fb440395349 did i miss something ? i have media module and my content has a media field
    – berramou
    Jul 29, 2022 at 11:05
  • 1
    This is not working for media which has multiple values. Dec 29, 2022 at 8:20

Your Answer

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

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