Last active
November 24, 2020 14:58
-
-
Save rr-it/f75774698c6bd995a56655f10a0c423e to your computer and use it in GitHub Desktop.
TYPO3 Powermail Issue on multi-line text in html mails
This file contains 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 characters
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::nl2brOnArray($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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment