Commit 884c68a7 authored by Stefan Galinski's avatar Stefan Galinski 🎮
Browse files

[BUGFIX] Fix formhandler integration, save mails

parent 13b46a6e
......@@ -28,7 +28,6 @@ namespace SGalinski\SgMail\Service;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Lang\LanguageService;
use Typoheads\Formhandler\Finisher\AbstractFinisher;
/**
......@@ -62,9 +61,6 @@ class FormhandlerFinisherService extends AbstractFinisher {
* @return array $gp
*/
public function process() {
/** @var $translator LanguageService */
$translator = (TYPO3_MODE === 'FE' ? $GLOBALS['TSFE'] : $GLOBALS['LANG']);
if (!isset($this->settings['to_address'])) {
$toAddressField = $this->settings['to_address_field'];
$toAddress = $this->gp[$toAddressField];
......@@ -72,16 +68,15 @@ class FormhandlerFinisherService extends AbstractFinisher {
$toAddress = $this->settings['to_address'];
}
$fromAddress = [$this->settings['from_address'] => $this->settings['from_name']];
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var \SGalinski\SgMail\Service\MailTemplateService $mailTemplateService */
$mailTemplateService = $objectManager->get(MailTemplateService::class);
$mailTemplateService->setToAddresses($toAddress);
$mailTemplateService->setFromAddress($fromAddress);
$mailTemplateService->setFromAddress($this->settings['from_address']);
$mailTemplateService->setTemplateName($this->settings['template_key']);
$mailTemplateService->setExtensionKey($this->settings['extension_key']);
$mailTemplateService->setMarkers($this->gp);
$mailTemplateService->setIgnoreMailQueue($this->settings['ignore_mail_queue'] == TRUE);
$mailTemplateService->sendEmail();
return $this->gp;
......
......@@ -115,7 +115,13 @@ class MailTemplateService {
* @var \SGalinski\SgMail\Domain\Repository\TemplateRepository
* @inject
*/
protected $templateRepository = NULL;
protected $templateRepository;
/**
* @var \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager
* @inject
*/
protected $persistenceManager;
/**
* MailTemplateService constructor.
......@@ -244,6 +250,7 @@ class MailTemplateService {
$emailBody = preg_replace('/(<br[\s]?[\/]?>[\s]*){3,}/', '<br /><br />', $emailBody);
if ($this->ignoreMailQueue) {
$this->addMailToMailQueue($subject, $emailBody, $this->priority, TRUE);
$this->mailMessage->setBody($emailBody, 'text/html');
$this->mailMessage->send();
} else {
......@@ -259,8 +266,9 @@ class MailTemplateService {
* @param string $subject
* @param string $emailBody
* @param int $priority
* @param bool $sent
*/
private function addMailToMailQueue($subject, $emailBody, $priority) {
private function addMailToMailQueue($subject, $emailBody, $priority, $sent = FALSE) {
/** @var ObjectManager $objectManager */
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
......@@ -272,9 +280,11 @@ class MailTemplateService {
$mail->setPriority($priority);
$mail->setBccAddresses(implode(',', $this->bccAddresses));
$mail->setCcAddresses(implode(',', $this->ccAddresses));
$mail->setSent($sent);
$mailRepository = $objectManager->get(MailRepository::class);
$mailRepository->add($mail);
$this->persistenceManager->persistAll();
}
/**
......@@ -286,7 +296,7 @@ class MailTemplateService {
}
/**
* @param array|string $toAddresses
* @param string $toAddresses
* @return MailTemplateService
*/
public function setToAddresses($toAddresses) {
......@@ -296,7 +306,7 @@ class MailTemplateService {
}
/**
* @param array|string $fromAddress
* @param string $fromAddress
* @return MailTemplateService
*/
public function setFromAddress($fromAddress) {
......@@ -316,7 +326,7 @@ class MailTemplateService {
}
/**
* @param array|string $replyToAddress
* @param string $replyToAddress
* @return MailTemplateService
*/
public function setReplyToAddress($replyToAddress) {
......
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