From b419790b3cbf164f16b4b2454c55f99c3a452cf9 Mon Sep 17 00:00:00 2001
From: Eric Bremner <ebremner@uwaterloo.ca>
Date: Fri, 10 Dec 2021 15:54:54 +0000
Subject: [PATCH] ISTWCMS-5214: updating get opportunity to handle specific
 teaser fields

---
 src/Service/UwNodeContent.php | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/src/Service/UwNodeContent.php b/src/Service/UwNodeContent.php
index 733a1db9..7eb1de98 100644
--- a/src/Service/UwNodeContent.php
+++ b/src/Service/UwNodeContent.php
@@ -86,7 +86,7 @@ class UwNodeContent {
         break;
 
       case 'uw_ct_opportunity':
-        $content_data = $this->getOpportunityContent($node_flags);
+        $content_data = $this->getOpportunityContent($node_flags, $view_mode);
         break;
     }
 
@@ -631,22 +631,31 @@ class UwNodeContent {
    *
    * @param array $node_flags
    *   The flags for the node.
+   * @param string $view_mode
+   *   The view mode for this node.
    *
    * @return array
    *   Array of content to get from the node.
    */
-  public function getOpportunityContent(array $node_flags): array {
+  public function getOpportunityContent(array $node_flags, string $view_mode): array {
 
     // Get the content data.
     $content_data = $this->setupContentData($node_flags);
 
     // Setup the header content.
     if ($node_flags['get_header']) {
-      $content_data['header']['opportunity_type'] = $this->addToContentData('terms', ['field_uw_opportunity_type']);
-      $content_data['header']['employment_type'] = $this->addToContentData('terms', ['field_uw_opportunity_employment']);
-      $content_data['header']['rate_of_pay'] = $this->addToContentData('plain_text', 'field_uw_opportunity_pay_rate');
-      $content_data['header']['rate_of_pay_type'] = $this->addToContentData('terms', ['field_uw_opportunity_pay_type']);
-      $content_data['header']['job_id'] = $this->addToContentData('plain_text', 'field_uw_opportunity_job_id');
+
+      if ($view_mode == 'teaser') {
+        $content_data['header']['posted'] = $this->addToContentData('date', 'field_uw_opportunity_date');
+        $content_data['header']['opportunity_type'] = $this->addToContentData('terms', ['field_uw_opportunity_type']);
+      }
+      else {
+        $content_data['header']['opportunity_type'] = $this->addToContentData('terms', ['field_uw_opportunity_type']);
+        $content_data['header']['employment_type'] = $this->addToContentData('terms', ['field_uw_opportunity_employment']);
+        $content_data['header']['rate_of_pay'] = $this->addToContentData('plain_text', 'field_uw_opportunity_pay_rate');
+        $content_data['header']['rate_of_pay_type'] = $this->addToContentData('terms', ['field_uw_opportunity_pay_type']);
+        $content_data['header']['job_id'] = $this->addToContentData('plain_text', 'field_uw_opportunity_job_id');
+      }
     }
 
     if ($node_flags['get_footer']) {
-- 
GitLab