You are here

public static function TextTrimmedFormatter::preRenderSummary in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/text/src/Plugin/Field/FieldFormatter/TextTrimmedFormatter.php \Drupal\text\Plugin\Field\FieldFormatter\TextTrimmedFormatter::preRenderSummary()

Pre-render callback: Renders a processed text element's #markup as a summary.

Parameters

array $element: A structured array with the following key-value pairs:

  • #markup: the filtered text (as filtered by filter_pre_render_text())
  • #format: containing the machine name of the filter format to be used to filter the text. Defaults to the fallback format. See filter_fallback_format().
  • #text_summary_trim_length: the desired character length of the summary (used by text_summary())

Return value

array The passed-in element with the filtered text in '#markup' trimmed.

See also

filter_pre_render_text()

text_summary()

File

core/modules/text/src/Plugin/Field/FieldFormatter/TextTrimmedFormatter.php, line 123

Class

TextTrimmedFormatter
Plugin implementation of the 'text_trimmed' formatter.

Namespace

Drupal\text\Plugin\Field\FieldFormatter

Code

public static function preRenderSummary(array $element) {
  $element['#markup'] = text_summary($element['#markup'], $element['#format'], $element['#text_summary_trim_length']);
  return $element;
}