Skip to content
Snippets Groups Projects
Commit 59c3a16a authored by Eric Bremner's avatar Eric Bremner Committed by Igor Biki
Browse files

ISTWCMS-5195: adding function to get formatted text

parent dcfb2d15
No related branches found
No related tags found
1 merge request!169Feature/istwcms 5195 ebremner node theming
...@@ -86,7 +86,7 @@ class UwNodeFieldValue { ...@@ -86,7 +86,7 @@ class UwNodeFieldValue {
// Long text field type with a text format. // Long text field type with a text format.
if ($type == 'formatted_text') { if ($type == 'formatted_text') {
return $node->$field_name->getValue()[0]; return $this->getFormattedText($node, $field_name);
} }
// Only content, either layout builder or summary. // Only content, either layout builder or summary.
...@@ -151,6 +151,25 @@ class UwNodeFieldValue { ...@@ -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. * Function to get catalog tags.
* *
...@@ -273,12 +292,9 @@ class UwNodeFieldValue { ...@@ -273,12 +292,9 @@ class UwNodeFieldValue {
*/ */
public function getContentField(Node $node, string $view_mode, string $field_name) { public function getContentField(Node $node, string $view_mode, string $field_name) {
// If on the teaser, return the summary field values.
if ($view_mode == 'teaser') { if ($view_mode == 'teaser') {
return [ return $this->getFormattedText($node, $field_name);
'#type' => 'processed_text',
'#text' => $node->$field_name->value,
'#format' => $node->$field_name->format,
];
} }
return NULL; 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