Commit a2b5fb6b authored by Torsten Oppermann's avatar Torsten Oppermann
Browse files

[TASK] Refactoring Test Mail & Controller for DB implementation. Fixed some bugs

parent 51822813
......@@ -98,6 +98,8 @@ class MailController extends ActionController {
);
}
$this->view->assign('selectedLanguageLeft', $this->settings['templateDefaultLanguage']);
$this->view->assign('selectedLanguageRight', $this->settings['templateDefaultLanguage']);
$this->view->assign('selectedTemplateKey', $secondLevelFirstEntry);
$this->view->assign('selectedExtensionKey', $firstEntry);
}
......
......@@ -3,7 +3,9 @@
namespace SGalinski\SgMail\Service;
use SGalinski\SgMail\Domain\Model\Mail;
use SGalinski\SgMail\Domain\Model\Template;
use SGalinski\SgMail\Domain\Repository\MailRepository;
use TYPO3\CMS\Core\Exception;
use TYPO3\CMS\Core\Mail\MailMessage;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
......@@ -110,6 +112,12 @@ class MailTemplateService {
*/
private $bccAddresses = [];
/**
* @var \SGalinski\SgMail\Domain\Repository\TemplateRepository
* @inject
*/
protected $templateRepository = NULL;
/**
* MailTemplateService constructor.
*/
......@@ -125,9 +133,27 @@ class MailTemplateService {
$this->mailMessage->setFrom($this->fromAddress);
$this->bccAddresses = GeneralUtility::trimExplode(',', $this->tsSettings['mail']['default']['bcc']);
$this->bccAddresses = GeneralUtility::trimExplode(',', $this->tsSettings['mail']['default']['cc']);
$this->mailMessage->setBcc($this->bccAddresses);
$this->mailMessage->setBcc($this->ccAddresses);
$this->ccAddresses = GeneralUtility::trimExplode(',', $this->tsSettings['mail']['default']['cc']);
foreach ($this->bccAddresses as $index => $email) {
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
unset($this->bccAddresses[$index]);
}
}
foreach ($this->ccAddresses as $index => $email) {
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
unset($this->ccAddresses[$index]);
}
}
if (sizeof($this->bccAddresses) > 0) {
$this->mailMessage->setBcc($this->bccAddresses);
}
if (sizeof($this->ccAddresses) > 0) {
$this->mailMessage->setCc($this->ccAddresses);
}
}
/**
......@@ -164,13 +190,16 @@ class MailTemplateService {
* Send the Email
*/
public function sendEmail() {
$templateEntry = self::$registerArray[$this->extensionKey][$this->templateName];
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var StandaloneView $emailView */
$emailView = $objectManager->get(StandaloneView::class);
$emailView->setTemplatePathAndFilename(
$templateEntry['templatePath'] . $this->language . '.sg_mail.locallang.html'
);
/** @var Template $template */
$template = $this->templateRepository->findTemplate(
$this->extensionKey, $this->templateName, $this->language
)->getFirst();
$emailView->setTemplateSource($template->getContent());
$emailView->assignMultiple($this->markers);
$emailBody = $emailView->render();
......@@ -179,7 +208,7 @@ class MailTemplateService {
$emailBody = nl2br($emailBody);
$emailBody = preg_replace('/(<br[\s]?[\/]?>[\s]*){3,}/', '<br /><br />', $emailBody);
$this->mailMessage->setSubject($this->subject);
$this->mailMessage->setSubject($template->getSubject());
$this->mailMessage->setBody($emailBody, 'text/html');
$this->mailMessage->send();
} else {
......@@ -327,5 +356,4 @@ class MailTemplateService {
return $this;
}
}
......@@ -10,7 +10,7 @@ module.tx_sgmail {
test.from = info@test.de
test.subject = This is just a Test E-Mail
default.from =
default.from = torsten@sgalinski.de
default.bcc =
default.cc =
}
......
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