Forked from rr-it/powermail-textarea_multiline-emails.diff
Created
November 24, 2020 14:58
-
-
Save mtness/5441bc775c9326f06cbcd6be9c176fa2 to your computer and use it in GitHub Desktop.
Revisions
-
rr-it revised this gist
Aug 24, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -48,7 +48,7 @@ diff -ru a/Classes/Utility/ArrayUtility.php b/Classes/Utility/ArrayUtility.php + $newArray = []; + foreach ((array)$array as $key => $value) { + if (is_array($value)) { + $newArray[$key] = self::nl2brOnArray($value); + } else { + $newArray[$key] = nl2br($value); + } -
rr-it created this gist
Aug 22, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,71 @@ diff -ru a/Classes/Domain/Repository/MailRepository.php b/Classes/Domain/Repository/MailRepository.php --- a/Classes/Domain/Repository/MailRepository.php 2017-08-22 15:27:42.155674340 +0200 +++ b/Classes/Domain/Repository/MailRepository.php 2017-08-22 14:52:23.296258864 +0200 @@ -381,7 +381,7 @@ * @param bool $htmlSpecialChars * @return array */ - public function getVariablesWithMarkersFromMail(Mail $mail, $htmlSpecialChars = false) + public function getVariablesWithMarkersFromMail(Mail $mail, $htmlSpecialChars = false, $nl2br = false) { $variables = []; foreach ($mail->getAnswers() as $answer) { @@ -392,11 +392,17 @@ if (is_array($value)) { $value = implode(', ', $value); } + if ($answer->getField()->getType() !== 'textarea') { + $value = preg_replace('#[\n\r]+#', ' ', $value); + } $variables[$answer->getField()->getMarker()] = $value; } if ($htmlSpecialChars) { $variables = ArrayUtility::htmlspecialcharsOnArray($variables); } + if ($nl2br) { + $variables = ArrayUtility::nl2brOnArray($variables); + } $signalArguments = [&$variables, $mail, $this]; $this->signalDispatch(__CLASS__, __FUNCTION__, $signalArguments); Only in b/Classes/Domain/Repository: MailRepository.php.orig diff -ru a/Classes/Utility/ArrayUtility.php b/Classes/Utility/ArrayUtility.php --- a/Classes/Utility/ArrayUtility.php 2017-08-22 15:27:42.219676014 +0200 +++ b/Classes/Utility/ArrayUtility.php 2017-08-22 14:52:23.296258864 +0200 @@ -79,4 +79,24 @@ unset($array); return $newArray; } + + /** + * Use nl2br on array (value only) (any depth - recursive call) + * + * @param array $array Any array + * @return array Nl2br'ed array + */ + public static function nl2brOnArray($array) + { + $newArray = []; + foreach ((array)$array as $key => $value) { + if (is_array($value)) { + $newArray[$key] = self::htmlspecialcharsOnArray($value); + } else { + $newArray[$key] = nl2br($value); + } + } + unset($array); + return $newArray; + } } diff -ru a/Classes/ViewHelpers/Misc/VariablesViewHelper.php b/Classes/ViewHelpers/Misc/VariablesViewHelper.php --- a/Classes/ViewHelpers/Misc/VariablesViewHelper.php 2017-08-22 15:27:42.319678628 +0200 +++ b/Classes/ViewHelpers/Misc/VariablesViewHelper.php 2017-08-22 14:52:23.296258864 +0200 @@ -67,7 +67,7 @@ $parseObject = $this->objectManager->get(StandaloneView::class); $parseObject->setTemplateSource($this->removePowermailAllParagraphTagWrap($this->renderChildren())); $parseObject->assignMultiple( - ArrayUtility::htmlspecialcharsOnArray($this->mailRepository->getVariablesWithMarkersFromMail($mail)) + $this->mailRepository->getVariablesWithMarkersFromMail($mail, true, true) ); $parseObject->assignMultiple( ArrayUtility::htmlspecialcharsOnArray($this->mailRepository->getLabelsWithMarkersFromMail($mail))