diff --git a/Classes/ViewHelpers/Format/ICalendarDescriptionViewHelper.php b/Classes/ViewHelpers/Format/ICalendarDescriptionViewHelper.php
index 2c76f286c..2435c6ca5 100644
--- a/Classes/ViewHelpers/Format/ICalendarDescriptionViewHelper.php
+++ b/Classes/ViewHelpers/Format/ICalendarDescriptionViewHelper.php
@@ -15,7 +15,7 @@
/**
* ICalendar Description viewhelper. Note, this ViewHelper does not escape output and should only be used
- * to process the iCal description field.
+ * to process the iCal description field and any other foldable ICal text fields.
*/
class ICalendarDescriptionViewHelper extends AbstractViewHelper
{
@@ -31,6 +31,7 @@ public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('description', 'string', 'The description', false);
+ $this->registerArgument('substractChars', 'integer', 'Amount of chars to substract from 75 in first line', false, 12);
}
/**
@@ -41,6 +42,8 @@ public function initializeArguments()
public function render(): string
{
$description = $this->arguments['description'] ?? null;
+ $substractChars = $this->arguments['substractChars'] ?? 0;
+ $firstLineMaxChars = 75 - $substractChars;
if ($description === null) {
$description = $this->renderChildren();
}
@@ -51,10 +54,10 @@ public function render(): string
$tmpDescription = str_replace(chr(13), '\n\n', $tmpDescription);
// Strip new lines
$tmpDescription = str_replace(chr(10), '', $tmpDescription);
- // Glue everything together, so every line is max 75 chars
- if (mb_strlen($tmpDescription) > 63) {
- $newDescription = mb_substr($tmpDescription, 0, 63) . chr(10);
- $tmpDescription = mb_substr($tmpDescription, 63);
+ // Glue everything together, so every line is max 75 chars respecting max. length of first line
+ if (mb_strlen($tmpDescription) > $firstLineMaxChars) {
+ $newDescription = mb_substr($tmpDescription, 0, $firstLineMaxChars) . chr(10);
+ $tmpDescription = mb_substr($tmpDescription, $firstLineMaxChars);
$arrPieces = mb_str_split($tmpDescription, 75);
foreach ($arrPieces as &$value) {
$value = ' ' . $value;
diff --git a/Tests/Unit/ViewHelpers/Format/ICalendarDescriptionViewHelperTest.php b/Tests/Unit/ViewHelpers/Format/ICalendarDescriptionViewHelperTest.php
index 68501ebec..50bc97a54 100644
--- a/Tests/Unit/ViewHelpers/Format/ICalendarDescriptionViewHelperTest.php
+++ b/Tests/Unit/ViewHelpers/Format/ICalendarDescriptionViewHelperTest.php
@@ -24,28 +24,39 @@ public function iCalendarDescriptionDataProvider(): array
return [
'emptyValue' => [
'',
+ 12,
'',
],
'shortDescriptionLess75Chars' => [
'This is just a short text with less than 75 chars',
+ 12,
'This is just a short text with less than 75 chars',
],
'shortDescriptionLess75CharsWithHtml' => [
'This is just a short text with less than 75 chars',
+ 12,
'This is just a short text with less than 75 chars',
],
'shortDescriptionLess75CharsWithHtmlAndLineBreak' => [
'This is just a short text with less than 75 chars' . chr(13) . ' and some more text',
+ 12,
'This is just a short text with less than 75 chars\n\n and some ' . chr(10) . ' more text',
],
'longDescriptionWithoutLineBreaks' => [
'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam',
+ 12,
'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed di' . chr(10) . ' am nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, s' . chr(10) . ' ed diam',
],
'longDescriptionWithLineBreaks' => [
'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam ' . chr(13) . 'nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam',
+ 12,
'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed di' . chr(10) . ' am \n\nnonumy eirmod tempor invidunt ut labore et dolore magna aliquyam era' . chr(10) . ' t, sed diam',
],
+ 'longDescriptionWithDifferentSubstractCharsOption' => [
+ 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam',
+ 48,
+ 'Lorem ipsum dolor sit amet,' . chr(10) . ' consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut lab' . chr(10) . ' ore et dolore magna aliquyam erat, sed diam',
+ ],
];
}
@@ -57,12 +68,13 @@ public function iCalendarDescriptionDataProvider(): array
* @dataProvider iCalendarDescriptionDataProvider
*
* @param mixed $value
+ * @param mixed $substractChars
* @param mixed $expected
*/
- public function viewHelperReturnsExpectedValues($value, $expected)
+ public function viewHelperReturnsExpectedValues($value, $substractChars, $expected)
{
$viewHelper = new ICalendarDescriptionViewHelper();
- $viewHelper->setArguments(['description' => $value]);
+ $viewHelper->setArguments(['description' => $value, 'substractChars' => $substractChars]);
$actual = $viewHelper->render();
self::assertEquals($expected, $actual);
}