From 7fe56267fa76fb0547534e1e825dc95b97f58404 Mon Sep 17 00:00:00 2001
From: Eric Bremner <ebremner@uwaterloo.ca>
Date: Wed, 10 Nov 2021 15:15:22 +0000
Subject: [PATCH] ISTWCMS-5195: fixing news getting node data

---
 src/Service/UwNodeContent.php | 50 +++++++++++++++++++++++++----------
 1 file changed, 36 insertions(+), 14 deletions(-)

diff --git a/src/Service/UwNodeContent.php b/src/Service/UwNodeContent.php
index 43608f25..f16f2c50 100644
--- a/src/Service/UwNodeContent.php
+++ b/src/Service/UwNodeContent.php
@@ -227,10 +227,12 @@ class UwNodeContent {
       $content_data['header']['author'] = $this->addToContentData('author', 'field_author');
     }
 
+    // Get the hero image.
     if ($node_flags['get_hero']) {
       $content_data['hero_image'] = $this->addToContentData('sources', 'field_uw_hero_image');
     }
 
+    // Get the listing image.
     if ($node_flags['get_listing_image']) {
       $content_data['listing_image'] = $this->addToContentData('sources', 'field_uw_blog_listing_page_image');
     }
@@ -273,10 +275,12 @@ class UwNodeContent {
       $content_data['header']['date'] = $this->addToContentData('date', 'field_uw_event_date');
     }
 
+    // Get hero image.
     if ($node_flags['get_hero']) {
       $content_data['hero_image'] = $this->addToContentData('sources', 'field_uw_hero_image');
     }
 
+    // Get listing image.
     if ($node_flags['get_listing_image']) {
       $content_data['listing_image'] = $this->addToContentData('sources', 'field_uw_event_listing_page_img');
     }
@@ -325,21 +329,39 @@ class UwNodeContent {
    */
   public function getNewsContent(array $node_flags): array {
 
-    // The list of tags for news.
-    $tag_list = [
-      'field_uw_news_tags',
-      'field_uw_audience',
-    ];
+    // Get the content data.
+    $content_data = $this->setupContentData($node_flags);
 
-    return [
-      'title' => $node_flags['get_title'] ? TRUE : NULL,
-      'url' => TRUE,
-      'date' => $node_flags['get_header'] ? 'field_uw_news_date' : NULL,
-      'sources' => $node_flags['get_image'] ? 'field_uw_news_listing_page_image' : NULL,
-      'hero' => $node_flags['get_image'] ? 'field_uw_hero_image' : NULL,
-      'content' => $node_flags['get_content'] ? 'field_uw_news_summary' : NULL,
-      'tags' => $node_flags['get_footer'] ? $tag_list : NULL,
-    ];
+    // Setup the header content.
+    if ($node_flags['get_header']) {
+      $content_data['header']['date'] = $this->addToContentData('date', 'field_uw_news_date');
+    }
+
+    // Get hero image.
+    if ($node_flags['get_hero']) {
+      $content_data['hero_image'] = $this->addToContentData('sources', 'field_uw_hero_image');
+    }
+
+    // Get listing image.
+    if ($node_flags['get_listing_image']) {
+      $content_data['listing_image'] = $this->addToContentData('sources', 'field_uw_news_listing_page_image');
+    }
+
+    // Setup the actual content.
+    if ($node_flags['get_content']) {
+      $content_data['content'] = $this->addToContentData('content', 'field_uw_news_summary');
+    }
+
+    // Get the tags.
+    $content_data['tags'] = $this->addToContentData(
+      'terms',
+      [
+        'field_uw_news_tags',
+        'field_uw_audience',
+      ]
+    );
+
+    return $content_data;
   }
 
   /**
-- 
GitLab