From 3114928ea8cd77073b2b9c880fa1977d8d5e249b Mon Sep 17 00:00:00 2001
From: Eric Bremner <ebremner@uwaterloo.ca>
Date: Tue, 14 Dec 2021 15:45:09 +0000
Subject: [PATCH] ISTWCMS-5266: adding logic on contact for which image to use

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

diff --git a/src/Service/UwNodeContent.php b/src/Service/UwNodeContent.php
index b707bcc3..8a2b21a2 100644
--- a/src/Service/UwNodeContent.php
+++ b/src/Service/UwNodeContent.php
@@ -74,7 +74,7 @@ class UwNodeContent {
         break;
 
       case 'uw_ct_contact':
-        $content_data = $this->getContactContent($node_flags);
+        $content_data = $this->getContactContent($node_flags, $view_mode);
         break;
 
       case 'uw_ct_profile':
@@ -467,11 +467,13 @@ class UwNodeContent {
    *
    * @param array $node_flags
    *   The flags for the node.
+   * @param string $view_mode
+   *   The view mode of the node.
    *
    * @return array
    *   Array of content to get from the node.
    */
-  public function getContactContent(array $node_flags): array {
+  public function getContactContent(array $node_flags, string $view_mode): array {
 
     // Get the content data.
     $content_data = $this->setupContentData($node_flags);
@@ -481,8 +483,19 @@ class UwNodeContent {
       $content_data['header']['position'] = $this->addToContentData('plain_text', 'field_uw_ct_contact_title');
     }
 
+    // If there is an image, we have to decide on which to get based
+    // on the view mode.
     if ($node_flags['get_image']) {
-      $content_data['image'] = $this->addToContentData('image', 'field_uw_ct_contact_image');
+
+      // If it is a teaser use the listing image, if not use the portrait image.
+      if ($view_mode == 'teaser') {
+        $content_data['image'] = $this->addToContentData('image', 'field_uw_contact_listing_image');
+      }
+      else {
+        $content_data['image'] = $this->addToContentData('image', 'field_uw_ct_contact_image');
+      }
+
+      // Add the extra options for portrait image style.
       $content_data['image']['extra_options'] = [
         'type' => 'portrait',
         'crop' => 'portrait',
-- 
GitLab