How can I programmatically render the summary of a textfield?

br flag

I can output a textarea field with the following code:


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?)

berliner avatar
bd flag
The documentation is here: [FieldItemBase::view]( and it points to [EntityViewBuilderInterface::viewFieldItem]( for the available options.
cn flag

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?


Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.