Commit 668e700b authored by Georgi's avatar Georgi
Browse files

Merge branch 'feature_1584_fix_contact_form_placeholders' into 'master'

[BUGFIX] 1584 fix contact form placeholders

See merge request !23
parents cfc394d1 748cad6b
......@@ -376,6 +376,7 @@ class NewsletterController extends ActionController {
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException
* @throws \BadFunctionCallException
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
* @throws \TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException
*/
public function sendTestMailAction(array $parameters = []) {
$arguments = [];
......@@ -426,21 +427,21 @@ class NewsletterController extends ActionController {
$mailTemplateService->setTemplateName($parameters['selectedTemplate']);
$mailTemplateService->setExtensionKey($parameters['selectedExtension']);
$mailTemplateService->setOverwrittenFromName($parameter['fromName']);
$mailTemplateService->setOverwrittenFromMail($parameter['fromMail']);
$mailTemplateService->setFromName($parameter['fromName']);
$mailTemplateService->setFromAddress($parameter['fromMail']);
$mailTemplateService->setSubject($parameter['subject']);
$mailTemplateService->setOverwrittenReplyTo($parameter['replyTo']);
$mailTemplateService->setReplyToAddress($parameter['replyTo']);
if (!$this->request->getArgument('sendRealEmails')) {
// Send test emails
$message = LocalizationUtility::translate('backend.success_mail', 'sg_mail');
foreach ((array) $parameters['templates'] as $key => $template) {
$mailTemplateService->setLanguage($key);
$mailTemplateService->setOverwrittenToAddresses($parameters['emailAddress']);
$mailTemplateService->setToAddresses($parameters['emailAddress']);
$mailTemplateService->setOverwrittenEmailBody($parameter['content']);
$mailTemplateService->setSubject($template['subject']);
$mailTemplateService->setOverWrittenFromName($template['fromName']);
$mailTemplateService->setOverWrittenFromMail($template['fromMail']);
$mailTemplateService->setFromName($template['fromName']);
$mailTemplateService->setFromAddress($template['fromMail']);
$mailTemplateService->setMarkers([
'user' => [
'username' => 'username@example.com',
......@@ -458,7 +459,7 @@ class NewsletterController extends ActionController {
'www' => ' www.example.com',
]
]);
$mailIsSend = $mailTemplateService->sendEmail(TRUE);
$mailIsSend = $mailTemplateService->sendEmail(TRUE, TRUE);
}
} else {
......@@ -479,8 +480,8 @@ class NewsletterController extends ActionController {
$mailTemplateService->setLanguage($key);
$mailTemplateService->setOverwrittenEmailBody($template['content']);
$mailTemplateService->setSubject($template['subject']);
$mailTemplateService->setOverwrittenBcc($template['bcc']);
$mailTemplateService->setOverwrittenCc($template['cc']);
$mailTemplateService->setBccAddresses($template['bcc']);
$mailTemplateService->setCcAddresses($template['cc']);
foreach ($recipients as $recipient) {
......@@ -489,7 +490,7 @@ class NewsletterController extends ActionController {
$mailTemplateService->setMarkers(['user' => $recipient]);
// no real error handling here, one must check the MailQueue
$mailTemplateService->sendEmail(FALSE);
$mailTemplateService->sendEmail(FALSE, TRUE);
} catch (\Exception $e) {
// Invalid email address could not be loaded to queue
$errorRecipients[] = $recipient['uid'] . ' - '
......
......@@ -123,36 +123,6 @@ class MailTemplateService {
*/
private $overwrittenEmailBody = '';
/**
* @var string $overwrittenBcc
*/
private $overwrittenBcc;
/**
* @var string $overwrittenFromName
*/
private $overwrittenFromName;
/**
* @var string $overwrittenFromMail
*/
private $overwrittenFromMail;
/**
* @var string $overwrittenReplyTo
*/
private $overwrittenReplyTo;
/**
* @var string $overwrittenToAddresses
*/
private $overwrittenToAddresses;
/**
* @var string $overwrittenCc
*/
private $overwrittenCc;
/**
* @var string $extensionKey
*/
......@@ -223,7 +193,7 @@ class MailTemplateService {
*/
private $subjectToSend;
/*
/**
* @var string
*/
private $defaultFromAddress;
......@@ -233,90 +203,6 @@ class MailTemplateService {
*/
private $defaultFromName;
/**
* @return string
*/
public function getOverwrittenBcc(): string {
return $this->overwrittenBcc;
}
/**
* @param string $overwrittenBcc
*/
public function setOverwrittenBcc(string $overwrittenBcc): void {
$this->overwrittenBcc = $overwrittenBcc;
}
/**
* @return string
*/
public function getOverwrittenCc(): string {
return $this->overwrittenCc;
}
/**
* @param string $overwrittenCc
*/
public function setOverwrittenCc(string $overwrittenCc): void {
$this->overwrittenCc = $overwrittenCc;
}
/**
* @return string
*/
public function getOverwrittenFromName(): string {
return $this->overwrittenFromName;
}
/**
* @param string $overwrittenFromName
*/
public function setOverwrittenFromName(string $overwrittenFromName): void {
$this->overwrittenFromName = $overwrittenFromName;
}
/**
* @return string
*/
public function getOverwrittenFromMail(): string {
return $this->overwrittenFromMail;
}
/**
* @param string $overwrittenFromMail
*/
public function setOverwrittenFromMail(string $overwrittenFromMail): void {
$this->overwrittenFromMail = $overwrittenFromMail;
}
/**
* @return string
*/
public function getOverwrittenReplyTo(): string {
return $this->overwrittenReplyTo;
}
/**
* @param string $overwrittenReplyTo
*/
public function setOverwrittenReplyTo(string $overwrittenReplyTo): void {
$this->overwrittenReplyTo = $overwrittenReplyTo;
}
/**
* @return string
*/
public function getOverwrittenToAddresses(): string {
return $this->overwrittenToAddresses;
}
/**
* @param string $overwrittenToAddresses
*/
public function setOverwrittenToAddresses(string $overwrittenToAddresses): void {
$this->overwrittenToAddresses = $overwrittenToAddresses;
}
/**
* MailTemplateService constructor.
*
......@@ -346,12 +232,14 @@ class MailTemplateService {
if (\filter_var($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'], FILTER_VALIDATE_EMAIL)) {
$this->fromAddress = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'];
$this->defaultFromAddress = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'];
} else if (!\filter_var($tsSettings['mail']['default']['from'], FILTER_VALIDATE_EMAIL)) {
$this->fromAddress = 'noreply@example.org';
$this->defaultFromAddress = 'noreply@example.org';
} else {
$this->fromAddress = $tsSettings['mail']['default']['from'];
$this->defaultFromAddress = $tsSettings['mail']['default']['from'];
if (!\filter_var($tsSettings['mail']['default']['from'], FILTER_VALIDATE_EMAIL)) {
$this->fromAddress = 'noreply@example.org';
$this->defaultFromAddress = 'noreply@example.org';
} else {
$this->fromAddress = $tsSettings['mail']['default']['from'];
$this->defaultFromAddress = $tsSettings['mail']['default']['from'];
}
}
if ($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName']) {
......@@ -785,6 +673,7 @@ class MailTemplateService {
* @return mixed
*/
protected function parseMarkers($text, $emailView) {
$text = (string) $text;
if (strpos($text, '{') !== FALSE) {
$emailView->setTemplateSource($text);
return $emailView->render();
......@@ -938,14 +827,19 @@ class MailTemplateService {
* @param RegisterService $registerService
* @param string $defaultTemplateContent
* @param int $siteRootId
* @param boolean $isNewsletter
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
*/
protected function extractValuesForMail($template, RegisterService $registerService, $defaultTemplateContent, $siteRootId): void {
protected function parseValuesForMail(
$template, RegisterService $registerService, $defaultTemplateContent,
$siteRootId
): void {
/** @var StandaloneView $emailView */
$emailView = $this->objectManager->get(StandaloneView::class);
$emailView->assignMultiple($this->markers);
$emailView->assign('all_fields', $this->getAllMarker($this->markers));
//TODO: make this as the lines below the next block
$overwrittenEmailBody = $this->getOverwrittenEmailBody();
$overwrittenSubject = '';
if ($this->subject !== '' && $this->subject !== NULL) {
......@@ -980,59 +874,31 @@ class MailTemplateService {
}
$this->setSubjectToSend($subject);
//TODO: is this object even in use somewhere?
$this->mailMessage->setSubject($subject);
if ($this->fromAddress === $this->defaultFromAddress) {
$fromMail = $this->parseMarkers(
empty($this->overwrittenFromMail) && $template ? $template->getFromMail() : $this->overwrittenFromMail,
$emailView
);
if ($fromMail) { // we don't want to override the default in that case
$this->setFromAddress($fromMail);
}
// Parse the markers
if ($this->fromName) {
$this->setFromName($this->parseMarkers($this->fromName, $emailView));
}
if ($this->fromName === $this->defaultFromName) {
$fromName = $this->parseMarkers(
(empty($this->overwrittenFromName) && $template ? $template->getFromName() : $this->overwrittenFromName),
$emailView
);
if ($fromName) { // we don't want to override the default if this value is empty here
$this->setFromName($fromName);
}
if ($this->fromAddress) {
$this->setFromAddress($this->parseMarkers($this->fromAddress, $emailView));
}
if ($this->replyToAddress === '') {
$replyTo = $this->parseMarkers(
(empty($this->overwrittenReplyTo) && $template ? $template->getReplyTo() : $this->overwrittenReplyTo),
$emailView
);
$this->setReplyToAddress($replyTo);
if ($this->replyToAddress) {
$this->setReplyToAddress($this->parseMarkers($this->replyToAddress, $emailView));
}
if (empty($this->ccAddresses)) {
$cc = $this->parseMarkers(
(empty($this->overwrittenCc) && $template ? $template->getCc() : $this->overwrittenCc),
$emailView
);
$this->setCcAddresses($cc);
if ($this->ccAddresses) {
$this->setCcAddresses($this->parseMarkers($this->ccAddresses, $emailView));
}
if (empty($this->bccAddresses)) {
$bcc = $this->parseMarkers(
(empty($this->overwrittenBcc) && $template ? $template->getBcc() : $this->overwrittenBcc),
$emailView
);
$this->setBccAddresses($bcc);
if ($this->bccAddresses) {
$this->setBccAddresses($this->parseMarkers($this->bccAddresses, $emailView));
}
if ($this->toAddresses === '') {
$toAddress = $this->parseMarkers(
(empty($this->overwrittenToAddresses) && $template ? $template->getToAddress() : $this->overwrittenToAddresses),
$emailView
);
$this->setToAddresses($toAddress);
if ($this->toAddresses) {
$this->setToAddresses($this->parseMarkers($this->toAddresses, $emailView));
}
// reset template source back to default
......@@ -1070,7 +936,7 @@ class MailTemplateService {
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException
*/
public function sendEmail($isPreview = FALSE): bool {
public function sendEmail($isPreview = FALSE, $isNewsletter = FALSE): bool {
if ($isPreview) { //TODO: remove this from here
$this->setIgnoreMailQueue(TRUE);
}
......@@ -1087,6 +953,11 @@ class MailTemplateService {
$registerService = GeneralUtility::makeInstance(RegisterService::class);
// Load the values from the template if they are set
if (!$isNewsletter && $template !== NULL) {
$this->loadTemplateValues($template);
}
// get default template content from register array
$defaultTemplateContent = $this->getDefaultTemplateContent($template, $registerService);
......@@ -1096,7 +967,7 @@ class MailTemplateService {
$this->setToAddresses(\trim($template->getToAddress()));
}
$this->extractValuesForMail($template, $registerService, $defaultTemplateContent, $siteRootId);
$this->parseValuesForMail($template, $registerService, $defaultTemplateContent, $siteRootId);
$mail = $this->addMailToMailQueue(
$this->extensionKey, $this->templateName, $this->getSubjectToSend(), $this->getMailBodyToSend(),
......@@ -1399,4 +1270,27 @@ class MailTemplateService {
return $allMarker;
}
/**
* use all values from the given template
*
* @param Template $template
*/
private function loadTemplateValues(Template $template): void {
$fromName = \trim($template->getFromName());
if ($fromName === '') {
$fromName = $this->fromName;
}
if ($fromName === '' && $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName']) {
$fromName = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName'];
}
$fromMail = $this->getValidFromMail(\trim($template->getFromMail()));
// The setters check if the value is empty or not
$this->setFromAddress($fromMail, $fromName);
$this->setCcAddresses($template->getCc());
$this->setBccAddresses($template->getBcc());
$this->setReplyToAddress($template->getReplyTo());
$this->setFromName($fromName);
}
}
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