From bd8026c1b711790b856a4fa6a1e10b3b6f2052a2 Mon Sep 17 00:00:00 2001
From: ebremner <ebremner@uwaterloo.ca>
Date: Mon, 4 Jun 2018 10:19:10 -0400
Subject: [PATCH] ISTWCMS-2447: Updating quicklinks to use responsive image and
 proper syntax

---
 ...agraph--uw-para-quicklinks-block.html.twig |  2 +-
 uw_fdsu_theme_resp.theme                      | 49 ++++++++++++++-----
 2 files changed, 38 insertions(+), 13 deletions(-)

diff --git a/templates/paragraphs/paragraph--uw-para-quicklinks-block.html.twig b/templates/paragraphs/paragraph--uw-para-quicklinks-block.html.twig
index 26961a13..a73a5f04 100644
--- a/templates/paragraphs/paragraph--uw-para-quicklinks-block.html.twig
+++ b/templates/paragraphs/paragraph--uw-para-quicklinks-block.html.twig
@@ -2,5 +2,5 @@
     'anchor_link': anchor_link,
     'display_title': display_title,
     'title': content.field_uw_block_title|field_value,
-    'quicklinks': content.field_uw_quicklink
+    'quicklinks': quicklinks
 } %}
\ No newline at end of file
diff --git a/uw_fdsu_theme_resp.theme b/uw_fdsu_theme_resp.theme
index d3a9f929..cab84970 100644
--- a/uw_fdsu_theme_resp.theme
+++ b/uw_fdsu_theme_resp.theme
@@ -126,21 +126,46 @@ function uw_fdsu_theme_resp_preprocess_paragraph(&$variables) {
       // Set the anchor link.
       $variables['anchor_link'] = _uw_fdsu_theme_resp_get_field_value_from_paragraph($variables['paragraph'], 'field_uw_anchor_link');
 
-      // Set the responsive image variables.
-     // _uw_fdsu_theme_resp_add_responsive_image_variables($variables, 'field_uw_icon_image', 'uw_resp_is_marketing_item');
+      $field_values = $variables['paragraph']->get('field_uw_quicklink')->getValue();
+
+      unset($quicklinks);
+      $counter = 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.
+        $paragraph = \Drupal\paragraphs\Entity\Paragraph::load($field_value['target_id']);
+
+        // Get the field entity from the paragraph.
+        $field = $paragraph->field_uw_icon_image->first();
 
-      // Set link section title
-      //$variables['quicklinks'] = _uw_fdsu_theme_resp_get_field_value_from_paragraph($variables['paragraph'], array(
-      //    [0] => [
-      //    'img_src' => 'field_uw_icon_image',
-      //    'link_section_title' => 'field_uw_link_section_title',
-      //    'links' => 'field_uw_quicklinks_links',
-      //]);
-//vardumper($variables['content']['field_uw_quicklink']);
+        // If there is a field to process, process it.
+        if (isset($field)) {
+          // Get the sources for the responsive image.
+          $quicklinks[$counter]['sources'] = _uw_fdsu_theme_resp_add_responsive_image_variables($variables, $field, 'uw_resp_is_marketing_item');
+        }
 
-$sources= _uw_fdsu_theme_resp_add_responsive_image_variables($variables['content']['field_uw_quicklink'][0], 'field_uw_icon_image', 'uw_resp_is_marketing_item', TRUE);
-vardumper($sources);
+        // Set the link section title.
+        $quicklinks[$counter]['link_section_title'] = $paragraph->get('field_uw_link_section_title')->getValue()[0]['value'];
+
+        // Get the links out of the quicklink paragraph.
+        $links = $paragraph->get('field_uw_quicklinks_links')->getValue();
+
+        // Step through each link and set the url and content.
+        foreach ($links as $link) {
+          $quicklinks[$counter]['links'][] = array(
+            'link_url' => $link['uri'],
+            'link_content' => $link['title']
+          );
+        }
+
+        // Increment the counter used for the quicklinks array.
+        $counter++;
+      }
 
+      // Set the quicklinks variable to be used in the template.
+      $variables['quicklinks'] = $quicklinks;
 
       break;
   }
-- 
GitLab