Created
November 21, 2018 16:56
-
-
Save adamdelaney/566d47176900281717e0772252129dfb to your computer and use it in GitHub Desktop.
Render responsive image from media entity reference field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$image_field = $paragraph->get('field_image'); | |
if (!$image_field->isEmpty()) { | |
$image = $image_field->first()->getValue(); | |
$media = Media::load($image['target_id']); | |
// Set display options. | |
$display_options = [ | |
'label' => 'hidden', | |
'type' => 'responsive_image', | |
'settings' => [ | |
'responsive_image_style' => 'uip_section', | |
], | |
]; | |
$variables['content']['section_image'] = $media->get('field_media_image')->view($display_options); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment