function TextTrimmedFormatter::addTrimPreRender
Attaches the trim pre-render callback and trim length to an element.
Subclasses that decide per item whether to trim can call this on the fallback branch.
Parameters
array $element: A processed_text render element to trim.
File
-
core/
modules/ text/ src/ Plugin/ Field/ FieldFormatter/ TextTrimmedFormatter.php, line 90
Class
- TextTrimmedFormatter
- Plugin implementation of the 'text_trimmed' formatter.
Namespace
Drupal\text\Plugin\Field\FieldFormatterCode
protected function addTrimPreRender(array &$element) : void {
// Make sure any default #pre_render callbacks are set on the element,
// because text_pre_render_summary() must run last.
$element += \Drupal::service('element_info')->getInfo($element['#type']);
$element['#pre_render'][] = [
static::class,
'preRenderSummary',
];
// Pass on the trim length to the #pre_render callback via a property.
$element['#text_summary_trim_length'] = $this->getSetting('trim_length');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.