I have a little problem to render media image content. I have a field with widget/formatter. The widget allow to select a media with drupal/media_library_form_element and to choose between available media "view modes".
Then the formatter will use the media and view mode to render the picture, like this :
// info contains media ID and view mode $info = unserialize($item->info); $media = Media::load($info['image']); $view = $this->entityTypeManager->getViewBuilder('media')->view($media, $info['image_view_mode']); $element['body'] = $view;
The problem is that drupal render always the image with "full" view mode.
Entity is a media entity, requested view-mode is "media.media_library" and exists into the system.
$view contains following :
[ '#media' => {the media entity}, '#view_mode' => 'media.media_library', '#cache' => {cache info} '#theme' => 'media', '#weight' => 0, '#pre_render' => [ 0 => [ 0 => {the entity view builder}, 1 => 'build', ] ] ]
If anyone can point my error it would be helpful 🙂
Thanks in advance for any suggestion.