I can output a textarea field with the following code:
$entity->fieldname->view();
How do I need to change that code for getting the summary of that field?
(Where can I find a documentation of that view-function?)
I can output a textarea field with the following code:
$entity->fieldname->view();
How do I need to change that code for getting the summary of that field?
(Where can I find a documentation of that view-function?)
You have to use the field formatter text_summary_or_trimmed
:
$build[] = $entity->fieldname->view([
'label' => 'hidden',
'type' => 'text_summary_or_trimmed',
'settings' => [
'trim_length' => 600,
],
]);
The easiest way to find the field formatter name and settings is configuring a field in a display mode of a content type and exporting the configuration.
How to find the documenation, see How to apply a Field Formatter to a node field programmatically?