2

I want to edit the Media library module View to show the images Alt and Title field value, but it is not in the available fields (only "Thumbnail(alt)" which prints the image).

All available relationships also do not give alt or title.

It seems the Image settings fields are not available in views?

4 Answers 4

4

alt and title are stored in field_media_image of the media type Image. To access the values in Views add this field to FIELDS and select/configure a field formatter to display the values.

To output the raw values outside of a formatted image rewrite the field and use the replacement patterns:

{{ field_media_image__title }}
{{ field_media_image__alt }}
2
  • Perfect! I added the field "Image" (of Category "Media") and then rewrote the result in the field itself with your replacement patterns, thanks!
    – petergus
    Nov 29, 2018 at 2:44
  • Same here. I used the field "Image" of media. And added the rewrite {{ image__alt }} to display the alt text. But I need to use the 'Combined Fields filter' and it does not seem like it can search that alt text? Nov 1, 2019 at 21:13
1

How to get it form media entity

{{ media_entity.field_media_image.title }}
{{ media_entity.field_media_image.alt }}

How to get it from node

{{ node.field_yourimagefield.entity.field_media_image.title }}
{{ node.field_yourimagefield.entity.field_media_image.alt }}
0

Not sure you'd easily get that info in a view.

Probably might need to do a hook_preprocess_media and add the content yourself as the view shows the rendered entity for the "media_library" display mode

Have a look at line 110 in the core/modules/media_library/media_library.module file and you'll see its doing a similar thing to add stuff to that rendered display

Or if you want this title to show just specifically for that view you could do an alter on that view

0

As none of the other answers worked for me, i had to search again. This finally worked:

content.field_news_image['#items'].entity.field_media_image.alt

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.