From d8cecfe15532dbf5baaa16a1e4a0969d7359fdda Mon Sep 17 00:00:00 2001
From: ebremner <ebremner@uwaterloo.ca>
Date: Mon, 24 Aug 2020 21:29:04 -0400
Subject: [PATCH] ISTWCMS-4027: ensuring that an image exists before adding
 source variable in uwService

---
 src/Service/UWService.php | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/Service/UWService.php b/src/Service/UWService.php
index b23eba37..5f0827b9 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':
-- 
GitLab