From 470cb44486162a82e647a32161e21a32a4f8496e Mon Sep 17 00:00:00 2001
From: Eric Bremner <ebremner@uwaterloo.ca>
Date: Mon, 29 Nov 2021 15:50:11 +0000
Subject: [PATCH] ISTWCMS-5204: fixing getting image styles

---
 src/Service/UWService.php          | 16 ++++++++++++++--
 src/Service/UWServiceInterface.php |  4 +++-
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/src/Service/UWService.php b/src/Service/UWService.php
index 032cfc37..e3d5f586 100644
--- a/src/Service/UWService.php
+++ b/src/Service/UWService.php
@@ -79,11 +79,14 @@ class UWService implements UWServiceInterface {
   /**
    * {@inheritDoc}
    */
-  public function getCropImageStyles(string $type): array {
+  public function getCropImageStyles(string $type, bool $get_all = FALSE): array {
+
+    // Image styles for portrait.
     $image_styles['portrait'] = [
       'uw_is_portrait',
     ];
 
+    // Image styles for responsive.
     $image_styles['responsive'] = [
       'uw_is_media_x_large',
       'uw_is_media_x_small',
@@ -92,7 +95,15 @@ class UWService implements UWServiceInterface {
       'uw_is_media_small',
     ];
 
-    return $image_styles[$type];
+    // If the flag to get all the image styles is set,
+    // return all of them.  If not return the
+    // specific image style.
+    if ($get_all) {
+      return $image_styles;
+    }
+    else {
+      return $image_styles[$type];
+    }
   }
 
   /**
@@ -156,6 +167,7 @@ class UWService implements UWServiceInterface {
       'uw_is_media_medium',
       'uw_is_media_small',
       'uw_is_media_x_small',
+      'uw_is_portrait',
     ];
   }
 
diff --git a/src/Service/UWServiceInterface.php b/src/Service/UWServiceInterface.php
index bfa26076..209b3577 100644
--- a/src/Service/UWServiceInterface.php
+++ b/src/Service/UWServiceInterface.php
@@ -19,11 +19,13 @@ interface UWServiceInterface {
    *
    * @param string $type
    *   The type of styles to get.
+   * @param bool $get_all
+   *   Flag to get all the image styles.
    *
    * @return string[]
    *   Array of image styles that are used.
    */
-  public function getCropImageStyles(string $type): array;
+  public function getCropImageStyles(string $type, bool $get_all = FALSE): array;
 
   /**
    * Prepares responsive image.
-- 
GitLab