diff --git a/src/Service/UWService.php b/src/Service/UWService.php index b23eba3785ea5a819ac828c5c347d5be7c4c00a8..5f0827b976e7518f41c8da52b9be20426c909a75 100644 --- a/src/Service/UWService.php +++ b/src/Service/UWService.php @@ -101,13 +101,17 @@ class UWService implements UWServiceInterface { // Get the image object from the node. $image = $node->$field_name->entity; - // Get all the image variables, including the sources using the prepareResponsiveImage function. - $image_variables = $this->prepareResponsiveImage($image, 'uw_ris_media'); + // Ensure that we have an image before adding variables. + if ($image !== NULL) { - // Set the responsive image variables for the teaser content. - $variables['sources'] = $image_variables['responsive_sources']; - $variables['img_element'] = $image_variables['img_element']['#uri']; - $variables['alt'] = $image->field_media_image->alt; + // Get all the image variables, including the sources using the prepareResponsiveImage function. + $image_variables = $this->prepareResponsiveImage($image, 'uw_ris_media'); + + // Set the responsive image variables for the teaser content. + $variables['sources'] = $image_variables['responsive_sources']; + $variables['img_element'] = $image_variables['img_element']['#uri']; + $variables['alt'] = $image->field_media_image->alt; + } break; case 'tags':