From 6cea29198ccddaaf071c75dc6eea85514aabf98a Mon Sep 17 00:00:00 2001
From: Eric Bremner <ebremner@uwaterloo.ca>
Date: Tue, 18 Oct 2022 10:42:28 -0400
Subject: [PATCH] ISTWCMS-5880: fixing getting media with in banners

---
 src/Service/UwNodeFieldValue.php | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/Service/UwNodeFieldValue.php b/src/Service/UwNodeFieldValue.php
index cc4f7033..d5d6367a 100644
--- a/src/Service/UwNodeFieldValue.php
+++ b/src/Service/UwNodeFieldValue.php
@@ -250,12 +250,14 @@ class UwNodeFieldValue {
     // Set the banners as empty in case we do not have any.
     $banners = [];
 
-    // Get the layout builder style based from the node value
-    // of media width.
-    $layout_builder_style = $layout_style = \Drupal::entityTypeManager()->getStorage('layout_builder_style')->load($node->field_uw_media_width->value);
+    if ($node->field_uw_media_width) {
+      // Get the layout builder style based from the node value
+      // of media width.
+      $layout_builder_style = $layout_style = \Drupal::entityTypeManager()->getStorage('layout_builder_style')->load($node->field_uw_media_width->value);
 
-    // Get the classes associated with the layout builder style.
-    $media_width_classes = $layout_builder_style->getClasses();
+      // Get the classes associated with the layout builder style.
+      $media_width_classes = $layout_builder_style->getClasses();
+    }
 
     // Process banner images.
     foreach ($node->$field_name as $banner_item) {
@@ -299,7 +301,7 @@ class UwNodeFieldValue {
         $banner['sources'] = $banner['image']['responsive_sources'];
         $banner['img_element'] = $banner['image']['img_element']['#uri'];
         $banner['alt'] = $banner['image']['alt'];
-        $banner['media_width'] = $media_width_classes;
+        $banner['media_width'] = $media_width_classes ?? NULL;
         unset($banner['image']);
       }
 
-- 
GitLab