From dd5787f626c43ae0da93b42f9c96d091433d1923 Mon Sep 17 00:00:00 2001
From: l26yan <l26yan@uwaterloo.ca>
Date: Tue, 29 May 2018 16:11:06 -0400
Subject: [PATCH] ISTWCMS-2448 Fix variables sources for options block

---
 uw_fdsu_theme_resp.theme | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/uw_fdsu_theme_resp.theme b/uw_fdsu_theme_resp.theme
index 11840908..2ed8565b 100644
--- a/uw_fdsu_theme_resp.theme
+++ b/uw_fdsu_theme_resp.theme
@@ -124,8 +124,14 @@ function uw_fdsu_theme_resp_preprocess_paragraph(&$variables) {
 
       //Get value from field_uw_options field;
       $field_values = $variables['paragraph']->get('field_uw_options')->getValue();
+
+      // Get the number of field_values.
+      $total_count = count($field_values);
+
+      // Define a counter.
       $i = 0;
 
+      // Process field_uw_options field which includes multiple entities.
       foreach ($field_values as $field_value) {
 
         // Get paragraph entity of field_uw_options field from the target_id.
@@ -168,7 +174,12 @@ function uw_fdsu_theme_resp_preprocess_paragraph(&$variables) {
 
             // Add all variables to an array.
             $options[$i]['img_element'] = $variables['img_element']['#uri'];
-            $options[$i]['sources'] = $variables['sources'][$i];
+
+            // Set sources because each entity has 5 responsive sources.
+            if ($i < $total_count){
+              $options[$i]['sources'] = (array_slice($variables['sources'], $i*5));
+            }
+
             $options[$i]['alt'] = $variables['alt'];
             $options[$i]['url'] = $variables['uri'];
             $options[$i]['responsive_image_style_id'] = $variables['responsive_image_style_id'];
@@ -178,6 +189,7 @@ function uw_fdsu_theme_resp_preprocess_paragraph(&$variables) {
         $i++;
       }
       $variables['options'] = $options;
+
       break;
   }
 }
-- 
GitLab