diff --git a/src/Service/UwNodeFieldValue.php b/src/Service/UwNodeFieldValue.php index 54ea1d80268864272889419a3b0caad0f047fbd9..e16f9e90e29a36ae81bc4daaa1608f1ac72bf362 100644 --- a/src/Service/UwNodeFieldValue.php +++ b/src/Service/UwNodeFieldValue.php @@ -86,7 +86,7 @@ class UwNodeFieldValue { // Long text field type with a text format. if ($type == 'formatted_text') { - return $node->$field_name->getValue()[0]; + return $this->getFormattedText($node, $field_name); } // Only content, either layout builder or summary. @@ -151,6 +151,25 @@ class UwNodeFieldValue { } } + /** + * Function to get the formatted text. + * + * @param \Drupal\node\Entity\Node $node + * The node. + * @param string $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 { + return [ + '#type' => 'processed_text', + '#text' => $node->$field_name->value, + '#format' => $node->$field_name->format, + ]; + } + /** * Function to get catalog tags. * @@ -273,12 +292,9 @@ class UwNodeFieldValue { */ public function getContentField(Node $node, string $view_mode, string $field_name) { + // If on the teaser, return the summary field values. if ($view_mode == 'teaser') { - return [ - '#type' => 'processed_text', - '#text' => $node->$field_name->value, - '#format' => $node->$field_name->format, - ]; + return $this->getFormattedText($node, $field_name); } return NULL;