From 1ffb2548c2f54a77fba2a03b43c98cc27e621090 Mon Sep 17 00:00:00 2001 From: Eric Bremner <ebremner@uwaterloo.ca> Date: Wed, 24 Nov 2021 16:53:48 +0000 Subject: [PATCH] ISTWCMS-5204: fixing contacts theming --- src/Service/UwNodeContent.php | 6 ++++-- src/Service/UwNodeFieldValue.php | 36 ++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/Service/UwNodeContent.php b/src/Service/UwNodeContent.php index 934ef7e2..29210f91 100644 --- a/src/Service/UwNodeContent.php +++ b/src/Service/UwNodeContent.php @@ -139,7 +139,9 @@ class UwNodeContent { $node_flags['get_hero'] = TRUE; } elseif ($view_mode == 'teaser') { - $node_flags['get_footer'] = FALSE; + if ($node->getType() !== 'uw_ct_contact') { + $node_flags['get_footer'] = FALSE; + } $node_flags['get_listing_image'] = TRUE; $node_flags['get_title'] = TRUE; } @@ -453,7 +455,7 @@ class UwNodeContent { // Setup the actual content. if ($node_flags['get_content']) { - $content_data['content'] = $this->addToContentData('content', 'field_uw_news_summary'); + $content_data['content'] = $this->addToContentData('content', NULL); } // Get the footer data. diff --git a/src/Service/UwNodeFieldValue.php b/src/Service/UwNodeFieldValue.php index 794ac06d..617ec10c 100644 --- a/src/Service/UwNodeFieldValue.php +++ b/src/Service/UwNodeFieldValue.php @@ -180,25 +180,29 @@ class UwNodeFieldValue { * * @param \Drupal\node\Entity\Node $node * The node. - * @param string $field_name + * @param string|null $field_name * The name of the field to get. * * @return array * Render array for formatted text. */ - public function getFormattedText(Node $node, string $field_name): array { - - // Get the value of the field. - $value = $node->$field_name->value; - - // If the value is not null, then return the - // formatted text render array. - if ($value !== NULL) { - return [ - '#type' => 'processed_text', - '#text' => $value, - '#format' => $node->$field_name->format, - ]; + public function getFormattedText(Node $node, string $field_name = NULL): array { + + // Ensure that we have a field to check. + if ($field_name !== NULL) { + + // Get the value of the field. + $value = $node->$field_name->value; + + // If the value is not null, then return the + // formatted text render array. + if ($value !== NULL) { + return [ + '#type' => 'processed_text', + '#text' => $value, + '#format' => $node->$field_name->format, + ]; + } } // If we get here there is no value, so @@ -371,13 +375,13 @@ class UwNodeFieldValue { * The node. * @param string $view_mode * The view mode. - * @param string $field_name + * @param string|null $field_name * The field name. * * @return array|null * Array of field value or NULL. */ - public function getContentField(Node $node, string $view_mode, string $field_name) { + public function getContentField(Node $node, string $view_mode, string $field_name = NULL): ?array { // If on the teaser, return the summary field values. if ($view_mode == 'teaser') { -- GitLab