Commit e9643878 authored by Stefan Galinski's avatar Stefan Galinski 🎮
Browse files

[BUGFIX] Fix missing checks of set default values of the mail forms

parent ceb5b748
......@@ -92,7 +92,7 @@ class FormsFinisher extends AbstractFinisher {
}
}
$templateName = $this->parseOption('template');
$templateName = trim($this->parseOption('template'));
if ($this->parseOption('template') === '') {
$templateName = $formDefinition->getIdentifier();
}
......@@ -107,12 +107,36 @@ class FormsFinisher extends AbstractFinisher {
$mailTemplateService->setIgnoreMailQueue($ignoreMailQueue);
$mailTemplateService->setLanguage($GLOBALS['TSFE']->config['config']['language']);
$mailTemplateService->setToAddresses($this->parseOption('mailTo'));
$mailTemplateService->setFromAddress($this->parseOption('mailFrom'));
$mailTemplateService->setFromName($this->parseOption('userName'));
$mailTemplateService->setReplyToAddress($this->parseOption('replyTo'));
$mailTemplateService->setCcAddresses($this->parseOption('cc'));
$mailTemplateService->setBccAddresses($this->parseOption('bcc'));
$mailToAdresses = trim($this->parseOption('mailTo'));
if ($mailToAdresses !== '') {
$mailTemplateService->setToAddresses($this->parseOption('mailTo'));
}
$fromAddress = trim($this->parseOption('mailFrom'));
if ($fromAddress !== '') {
$mailTemplateService->setFromAddress($fromAddress);
}
$fromName = trim($this->parseOption('userName'));
if ($fromName !== '') {
$mailTemplateService->setFromName($fromName);
}
$replyTo = trim($this->parseOption('replyTo'));
if ($replyTo !== '') {
$mailTemplateService->setReplyToAddress($replyTo);
}
$ccAddresses = trim($this->parseOption('cc'));
if ($ccAddresses !== '') {
$mailTemplateService->setCcAddresses($ccAddresses);
}
$bccAddresses = trim($this->parseOption('bcc'));
if ($bccAddresses !== '') {
$mailTemplateService->setBccAddresses($bccAddresses);
}
$mailTemplateService->sendEmail();
}
......
......@@ -206,11 +206,11 @@ class MailTemplateService {
}
}
if (count($this->bccAddresses) > 0) {
if (\count($this->bccAddresses) > 0) {
$this->mailMessage->setBcc($this->bccAddresses);
}
if (count($this->ccAddresses) > 0) {
if (\count($this->ccAddresses) > 0) {
$this->mailMessage->setCc($this->ccAddresses);
}
}
......@@ -223,7 +223,7 @@ class MailTemplateService {
* @param string $extensionKey
* @return array
*/
public static function getDefaultTemplateMarker($translationKey, array $marker, $extensionKey = 'sg_mail') {
public static function getDefaultTemplateMarker($translationKey, array $marker, $extensionKey = 'sg_mail'): array {
$languagePath = 'LLL:EXT:' . $extensionKey . '/Resources/Private/Language/locallang.xlf:' . $translationKey;
// Need the key for translations
......@@ -267,8 +267,9 @@ class MailTemplateService {
}
if ($this->pid) {
$pageUid = (int) $this->pid;
$pageUid = $this->pid;
}
if ($pageUid === 0) {
$pageRepository = $this->objectManager->get(PageRepository::class);
$rootPageRows = $pageRepository->getRecordsByField(
......@@ -297,15 +298,14 @@ class MailTemplateService {
}
// get default template content from register array
$defaultTemplateContent = $registerService->getRegisterArray(
)[$this->extensionKey][$this->templateName]['templateContent'];
// var_dump($registerService->getRegisterArray()[$this->extensionKey][$this->templateName]); die();
// var_dump($defaultTemplateContent); die();
$defaultTemplateContent = $registerService->getRegisterArray()
[$this->extensionKey][$this->templateName]['templateContent'];
// If there is no template for this language, use the default template
if ($template === NULL) {
if ($defaultTemplateContent === NULL) {
$templatePath = $registerService->getRegisterArray(
)[$this->extensionKey][$this->templateName]['templatePath'];
$templatePath = $registerService->getRegisterArray()
[$this->extensionKey][$this->templateName]['templatePath'];
// only standard template file is considered since version 4.1
$defaultTemplateFile = $templatePath . 'template.html';
......@@ -334,8 +334,8 @@ class MailTemplateService {
if ($isPreview) {
$previewMarker = [];
/** @var array $markerArray */
/** @var array $markerArray */
$markerArray = $registerService->getRegisterArray()[$this->extensionKey][$this->templateName]['marker'];
foreach ($markerArray as $marker) {
$markerPath = GeneralUtility::trimExplode('.', $marker['marker']);
......@@ -373,7 +373,8 @@ class MailTemplateService {
$subject = $registerService->getRegisterArray()[$this->extensionKey][$this->templateName]['subject'];
if (\is_array($subject)) {
$subject = \trim(
$registerService->getRegisterArray()[$this->extensionKey][$this->templateName]['subject'][$this->language]
$registerService->getRegisterArray()
[$this->extensionKey][$this->templateName]['subject'][$this->language]
);
}
if ($subject === NULL && $this->subject !== NULL) {
......@@ -543,7 +544,7 @@ class MailTemplateService {
* @param string $toAddresses
* @return MailTemplateService
*/
public function setToAddresses($toAddresses) {
public function setToAddresses($toAddresses): MailTemplateService {
$toAddresses = trim(preg_replace('~\x{00a0}~siu', ' ', $toAddresses));
$this->toAddresses = $toAddresses;
......@@ -560,7 +561,7 @@ class MailTemplateService {
* @param string $fromName
* @return MailTemplateService
*/
public function setFromAddress($fromAddress, $fromName = '') {
public function setFromAddress($fromAddress, $fromName = ''): MailTemplateService {
if ($fromAddress) {
$this->fromAddress = $fromAddress;
$this->mailMessage->setFrom($fromAddress, $fromName);
......@@ -573,7 +574,7 @@ class MailTemplateService {
* @param string $ccAddresses
* @return MailTemplateService
*/
public function setCcAddresses($ccAddresses) {
public function setCcAddresses($ccAddresses): MailTemplateService {
if ($ccAddresses) {
$this->ccAddresses = $ccAddresses;
$this->mailMessage->setCc(GeneralUtility::trimExplode(',', $this->ccAddresses));
......@@ -586,7 +587,7 @@ class MailTemplateService {
* @param string $replyToAddress
* @return MailTemplateService
*/
public function setReplyToAddress($replyToAddress) {
public function setReplyToAddress($replyToAddress): MailTemplateService {
if ($replyToAddress) {
$this->replyToAddress = $replyToAddress;
$this->mailMessage->setReplyTo($replyToAddress);
......@@ -599,7 +600,7 @@ class MailTemplateService {
* @param string $language
* @return MailTemplateService
*/
public function setLanguage($language) {
public function setLanguage($language): MailTemplateService {
$this->language = $language;
return $this;
}
......@@ -608,7 +609,7 @@ class MailTemplateService {
* @param boolean $ignoreMailQueue
* @return MailTemplateService
*/
public function setIgnoreMailQueue($ignoreMailQueue) {
public function setIgnoreMailQueue($ignoreMailQueue): MailTemplateService {
$this->ignoreMailQueue = $ignoreMailQueue;
return $this;
}
......@@ -617,7 +618,7 @@ class MailTemplateService {
* @param string $templateName
* @return MailTemplateService
*/
public function setTemplateName($templateName) {
public function setTemplateName($templateName): MailTemplateService {
$this->templateName = $templateName;
return $this;
}
......@@ -626,7 +627,7 @@ class MailTemplateService {
* @param string $extensionKey
* @return MailTemplateService
*/
public function setExtensionKey($extensionKey) {
public function setExtensionKey($extensionKey): MailTemplateService {
$this->extensionKey = $extensionKey;
return $this;
}
......@@ -635,7 +636,7 @@ class MailTemplateService {
* @param array $markers
* @return MailTemplateService
*/
public function setMarkers(array $markers) {
public function setMarkers(array $markers): MailTemplateService {
$this->markers = $markers;
return $this;
}
......@@ -644,7 +645,7 @@ class MailTemplateService {
* @param string $bccAddresses
* @return MailTemplateService
*/
public function setBccAddresses($bccAddresses) {
public function setBccAddresses($bccAddresses): MailTemplateService {
if ($bccAddresses) {
$this->bccAddresses = $bccAddresses;
$this->mailMessage->setBcc(GeneralUtility::trimExplode(',', $this->bccAddresses));
......@@ -657,7 +658,7 @@ class MailTemplateService {
* @param int $priority
* @return MailTemplateService
*/
public function setPriority($priority) {
public function setPriority($priority): MailTemplateService {
$this->priority = $priority;
return $this;
}
......@@ -668,7 +669,7 @@ class MailTemplateService {
* @param string $contentType
* @return MailTemplateService
*/
public function addAttachment($data, $filename, $contentType) {
public function addAttachment($data, $filename, $contentType): MailTemplateService {
$attachment = Swift_Attachment::newInstance()
->setFilename($filename)
->setContentType($contentType)
......@@ -683,7 +684,7 @@ class MailTemplateService {
* @param FileInterface|FileReference $file
* @return MailTemplateService
*/
public function addFileResourceAttachment($file) {
public function addFileResourceAttachment($file): MailTemplateService {
if ($file instanceof FileReference) {
$file = $file->getOriginalResource()->getOriginalFile();
}
......@@ -706,7 +707,7 @@ class MailTemplateService {
/**
* @return MailMessage
*/
public function getMailMessage() {
public function getMailMessage(): MailMessage {
return $this->mailMessage;
}
......@@ -774,7 +775,7 @@ class MailTemplateService {
* @param int $pid
* @return MailTemplateService
*/
public function setPid($pid) {
public function setPid($pid): MailTemplateService {
$this->pid = (int) $pid;
return $this;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment