0

I have a formatted text field on a content type that I'm using as the body of an email. If I load the node and print out the field I get:

>>> $n->field_thankyou_email_body->getValue() => [ [ "value" => "<b>Thanks!!</b>", "format" => "subscriber_text_lb", ], ] 

The array is missing the "processed" value, how do I get that? Or alternatively how do I manually run the value through the text format?

1 Answer 1

2

A field property is accessed like an object property:

$node->field_formatted_text->processed 

As a side note, use this only for cases like this which are outside of the page render context. The preferable way is to render the text field in a render array to preserve attached metadata. See How to safely render node body on a custom variable?

3
  • oh so even though the debug doesn't show it, the property is accessible, thanks. Commented Jul 25, 2022 at 15:32
  • Yes, this is because it is a computed property. Like entity of a reference field or date of a datetime field. See drupal.stackexchange.com/a/252341/47547 Commented Jul 25, 2022 at 15:38
  • I'm getting object unless I typecast as below, (string) $entity->get('field_formatted_text')->processed; Commented Jul 31, 2023 at 8:34

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.