diff --git a/Classes/ViewHelpers/Format/WordWrapViewHelper.php b/Classes/ViewHelpers/Format/WordWrapViewHelper.php new file mode 100644 index 0000000..9937345 --- /dev/null +++ b/Classes/ViewHelpers/Format/WordWrapViewHelper.php @@ -0,0 +1,75 @@ +registerArgument('subject', 'string', 'Text to wrap'); + $this->registerArgument('limit', 'integer', 'Maximum length of resulting parts after wrapping', false, 80); + $this->registerArgument('break', 'string', 'Character to wrap text at', false, PHP_EOL); + $this->registerArgument('glue', 'string', 'Character to concatenate parts with after wrapping', false, PHP_EOL); + } + + /** + * @param array $arguments + * @param \Closure $renderChildrenClosure + * @param RenderingContextInterface $renderingContext + * @return mixed + */ + public static function renderStatic( + array $arguments, + \Closure $renderChildrenClosure, + RenderingContextInterface $renderingContext + ) { + $subject = $renderChildrenClosure(); + $limit = (integer) $arguments['limit']; + $break = $arguments['break']; + $glue = $arguments['glue']; + $subject = preg_replace('/ +/', ' ', $subject); + $subject = str_replace(["\r\n", "\r"], PHP_EOL, $subject); + $subject = wordwrap($subject, $limit, $break, false); + $output = ''; + foreach (explode($break, $subject) as $line) { + if (mb_strlen($line) <= $limit) { + $output .= $line . $glue; + continue; + } + $temp = ''; + //while (mb_strlen($line) > $limit) { + // $temp .= mb_substr($line, 0, $limit - 1); + // $line = mb_substr($line, $limit - 1); + //} + if (false === empty($temp)) { + $output .= $temp . $glue . $line . $glue; + } else { + $output .= $line . $glue; + } + } + return $output; + } +} diff --git a/Resources/Private/Partials/Mails/DefaultText.html b/Resources/Private/Partials/Mails/DefaultText.html index ff9aa5b..1217784 100644 --- a/Resources/Private/Partials/Mails/DefaultText.html +++ b/Resources/Private/Partials/Mails/DefaultText.html @@ -20,9 +20,9 @@ ### {row.data -> f:format.nl2br() -> f:format.raw()} - + {row.data -> f:format.raw()} - + {br}{br}