From ac985a98dbe4e97158b3b174a0516410c0fd2dcc Mon Sep 17 00:00:00 2001 From: ebremner <ebremner@uwaterloo.ca> Date: Thu, 17 Jun 2021 09:28:24 -0400 Subject: [PATCH] ISTWCMS-4704: adding function to check for featured image --- src/Service/UWService.php | 33 ++++++++++++++++++++++++++++++ src/Service/UWServiceInterface.php | 11 ++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/Service/UWService.php b/src/Service/UWService.php index f96a8695..54cc7781 100644 --- a/src/Service/UWService.php +++ b/src/Service/UWService.php @@ -370,6 +370,39 @@ class UWService implements UWServiceInterface { ]; } + /** + * {@inheritDoc} + */ + public function uwCheckNodeForFeaturedImage(Node $node): string { + + // Set the node type. + $node_type = $node->getType(); + + // Get the list of content types that are allowed to have + // feature images from our service. + $featured_image = $this->uwGetFeaturedImageContentTypes(); + + // If node is allowed to have a featured image, make sure that + // node actually has an image. + if (in_array($node_type, array_keys($featured_image))) { + + // Get the field name. + $field_name = $featured_image[$node_type]; + + // Get the image object values from the node. + $image = $node->$field_name->getValue(); + + // If there is an image present, set the variable so that + // the page title will not be displayed. + if ($image) { + return 'yes'; + } + else { + return 'no'; + } + } + } + /** * {@inheritDoc} */ diff --git a/src/Service/UWServiceInterface.php b/src/Service/UWServiceInterface.php index 576830ea..00ede8c0 100644 --- a/src/Service/UWServiceInterface.php +++ b/src/Service/UWServiceInterface.php @@ -66,6 +66,17 @@ interface UWServiceInterface { */ public function uwGetFeaturedImageContentTypes(): array; + /** + * Gets dates from node. + * + * @param \Drupal\node\Node $node + * Node entity. + * + * @return string + * Yes or no. + */ + public function uwCheckNodeForFeaturedImage(Node $node): string; + /** * Gets dates from node. * -- GitLab