From 452a3b4d2761984ba87ebc682dbc17b84a7f1aa5 Mon Sep 17 00:00:00 2001 From: ebremner <ebremner@uwaterloo.ca> Date: Thu, 17 Jun 2021 01:22:26 -0400 Subject: [PATCH] ISTWCMS-4704: adding logic for featured images on nodes --- src/Service/UWService.php | 20 ++++++++++++++++++-- src/Service/UWServiceInterface.php | 8 ++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/Service/UWService.php b/src/Service/UWService.php index f9e725c8..62c123f3 100644 --- a/src/Service/UWService.php +++ b/src/Service/UWService.php @@ -114,6 +114,8 @@ class UWService implements UWServiceInterface { $get_content = FALSE; $get_title = TRUE; + $featured_image = $this->uwGetFeaturedImageContentTypes(); + // Setup flags based on teaser content argument. if ($content == 'all') { $get_header = TRUE; @@ -126,7 +128,10 @@ class UWService implements UWServiceInterface { if ($view_mode == 'full') { $get_title = FALSE; - $get_image = TRUE; + + if (in_array($node->getType(), array_keys($featured_image))) { + $get_image = TRUE; + } } } else { @@ -222,7 +227,7 @@ class UWService implements UWServiceInterface { 'title' => $get_title ? TRUE : NULL, 'sub_title' => $get_header ? 'field_uw_ct_contact_title' : NULL, 'affiliation' => $get_header ? 'field_uw_ct_contact_affiliation' : NULL, - 'image' => $get_header ? 'field_uw_ct_contact_image' : NULL, + 'image' => $get_image ? 'field_uw_ct_contact_image' : NULL, 'content' => $get_content ? 'layout_builder__layout' : NULL, 'email' => $get_footer ? 'field_uw_ct_contact_email' : NULL, 'location' => $get_footer ? 'field_uw_ct_contact_location' : NULL, @@ -353,6 +358,17 @@ class UWService implements UWServiceInterface { return $node_data; } + /** + * {@inheritDoc} + */ + public function uwGetFeaturedImageContentTypes(): array { + return [ + 'uw_ct_blog' => 'field_uw_blog_listing_page_image', + 'uw_ct_event' => 'field_uw_event_listing_page_img', + 'uw_ct_news_item' => 'field_uw_news_listing_page_image', + ]; + } + /** * {@inheritDoc} */ diff --git a/src/Service/UWServiceInterface.php b/src/Service/UWServiceInterface.php index 60b58a64..576830ea 100644 --- a/src/Service/UWServiceInterface.php +++ b/src/Service/UWServiceInterface.php @@ -58,6 +58,14 @@ interface UWServiceInterface { */ public function uwGetNodeData(Node $node, string $view_mode, array $content_data): array; + /** + * Gets content types that have feature images. + * + * @return array + * Array of content types that has featured images. + */ + public function uwGetFeaturedImageContentTypes(): array; + /** * Gets dates from node. * -- GitLab