Media Entity

Drupal 8: Get URI, Title, and Alt from Media Entity Reference Item

Over the last several days, I've railed in my head against the matroshka structure of Drupal entities. But when I tried to break out some helper functions, and when I realized what each of the different properties each entity had, I realized the complexities of entities were warranted. Life is complex, and thus Drupal is complex.

Entity references load a Media Entity, which load an Image from an image field, which load a File. The alt and title are on the Image, while the file URI is on the file.

Get File URI from Media Entity Reference Item in Drupal 8 OR Wrong File Loaded

Another day learning Drupal 8, but today is troubling.

Here's where I'm at. I'm theming search results, and I need to load field values to pass to twig templates—specifically a styled url for img src.

Entities values are not loaded on search results, only little snippets, so I have to load them the hard way, because we want images and nice theming on our search results.

Subscribe to Media Entity