1

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

1

1 Answer 1

6

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.