Skip to content
Snippets Groups Projects
Commit 3c49f508 authored by Eric Bremner's avatar Eric Bremner
Browse files

ISTWCMS-5195: adding function to get formatted text

parent 750feb53
No related branches found
No related tags found
1 merge request!172Feature/istwcms 5128 ebremner theme node services
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment