` element will be counted as characters. * * ``` * * This is some very long text * * ``` * * @see https://docs.typo3.org/permalink/t3viewhelper:typo3-fluid-format-crop */ final class CropViewHelper extends AbstractViewHelper { /** * The output may contain HTML and can not be escaped. * * @var bool */ protected $escapeOutput = false; public function __construct( private readonly TextCropper $textCropper, private readonly HtmlCropper $htmlCropper, ) {} public function initializeArguments(): void { $this->registerArgument('maxCharacters', 'int', 'Place where to truncate the string', true); $this->registerArgument('append', 'string', 'What to append, if truncation happened', false, '…'); $this->registerArgument('respectWordBoundaries', 'bool', 'If TRUE and division is in the middle of a word, the remains of that word is removed.', false, true); $this->registerArgument('respectHtml', 'bool', 'If TRUE the cropped string will respect HTML tags and entities. Technically that means, that cropHTML() is called rather than crop()', false, true); } public function render(): string { $maxCharacters = (int)$this->arguments['maxCharacters']; $append = (string)$this->arguments['append']; $respectWordBoundaries = (bool)($this->arguments['respectWordBoundaries']); $respectHtml = (bool)$this->arguments['respectHtml']; $stringToTruncate = (string)$this->renderChildren(); return $respectHtml ? $this->htmlCropper->crop($stringToTruncate, $maxCharacters, $append, $respectWordBoundaries) : $this->textCropper->crop($stringToTruncate, $maxCharacters, $append, $respectWordBoundaries); } }