Skip to content

Instantly share code, notes, and snippets.

@adamdelaney
Created November 21, 2018 16:56
Show Gist options
  • Save adamdelaney/566d47176900281717e0772252129dfb to your computer and use it in GitHub Desktop.
Save adamdelaney/566d47176900281717e0772252129dfb to your computer and use it in GitHub Desktop.
Render responsive image from media entity reference field
$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