Skip to content
Snippets Groups Projects
Commit 9874d11e authored by Eric Bremner's avatar Eric Bremner Committed by Igor Biki
Browse files

ISTWCMS-5195: updating prepareResponsiveImage to ensure that entities are not null

parent ca752792
No related branches found
No related tags found
1 merge request!169Feature/istwcms 5195 ebremner node theming
...@@ -81,31 +81,35 @@ class UWService implements UWServiceInterface { ...@@ -81,31 +81,35 @@ class UWService implements UWServiceInterface {
*/ */
public function prepareResponsiveImage(EntityInterface $entity, string $image_style): array { public function prepareResponsiveImage(EntityInterface $entity, string $image_style): array {
// Load in the file object if we have one. // Ensure that we can load an entity on the media.
if ($file = $entity->field_media_image->entity) { if (isset($entity->field_media_image->entity)) {
// Need to set these variables so that responsive image function, // Load in the file object if we have one.
// has all the necessary info to process the image style. if ($file = $entity->field_media_image->entity) {
$variables['uri'] = $file->getFileUri();
$variables['responsive_image_style_id'] = $image_style; // Need to set these variables so that responsive image function,
// has all the necessary info to process the image style.
// Set the alt for the image. $variables['uri'] = $file->getFileUri();
$variables['alt'] = $entity->field_media_image->alt; $variables['responsive_image_style_id'] = $image_style;
// These is a function from the responsive image module that sets all // Set the alt for the image.
// the variables for the sources of the responsive image. $variables['alt'] = $entity->field_media_image->alt;
template_preprocess_responsive_image($variables);
// These is a function from the responsive image module that sets all
// Step through each of the sources and setup our own sources array. // the variables for the sources of the responsive image.
foreach ($variables['sources'] as $source) { template_preprocess_responsive_image($variables);
$variables['responsive_sources'][] = [
'srcset' => $source->storage()['srcset']->value(), // Step through each of the sources and setup our own sources array.
'media' => $source->storage()['media']->value(), foreach ($variables['sources'] as $source) {
'type' => $source->storage()['type']->value(), $variables['responsive_sources'][] = [
]; 'srcset' => $source->storage()['srcset']->value(),
} 'media' => $source->storage()['media']->value(),
'type' => $source->storage()['type']->value(),
];
}
return $variables; return $variables;
}
} }
return []; return [];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment