Newer
Older
<?php
declare(strict_types=1);
namespace SGalinski\SgMail\Finisher\Forms;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (https://www.sgalinski.de)
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use SGalinski\SgMail\Service\MailTemplateService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher;
* This finisher sends an email via sg_mail after form submission and enables customization of mail markers
*/
class FormsFinisher extends AbstractFinisher {
/**
* This contains type names of fields we dont care about in sgmail
*
* @var array
*/
const IGNORE_FIELDS = [
'Honeypot', 'Hidden'
];
*
* Send email with the sgmail api to one or more recipients
* overwrites the mail markers with custom identifiers if provided
*
* @see AbstractFinisher::execute()
*
* @throws \InvalidArgumentException
* @throws \BadFunctionCallException
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
*/
protected function executeInternal() {
$formValues = $this->finisherContext->getFormValues();
$formRuntime = $this->finisherContext->getFormRuntime();
// check if all the necessary objects exist
if ($formRuntime !== NULL) {
$formDefinition = $formRuntime->getFormDefinition();
} else {
return;
}
if ($formRuntime === NULL) {
return;
}
$markers = [];
foreach ($formValues as $identifier => $value) {
$formElement = $formDefinition->getElementByIdentifier($identifier);
if (!$formElement) {
continue;
}
$type = $formElement->getType();
if (\in_array($type, self::IGNORE_FIELDS, TRUE)) {
continue;
}
$formElemenProperties = $formElement->getProperties();
if (isset($formElemenProperties['markerName']) && \trim($formElemenProperties['markerName']) !== '') {
$markers[\trim($formElemenProperties['markerName'])] = $value;
} else {
$markers[$identifier] = $value;
}
}

Torsten Oppermann
committed
$templateName = trim($this->parseOption('template'));

Torsten Oppermann
committed
if ($this->parseOption('template') === '') {
$templateName = $formDefinition->getIdentifier();
}
$ignoreMailQueue = (boolean) $this->parseOption('ignoreMailQueue');
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var \SGalinski\SgMail\Service\MailTemplateService $mailTemplateService */
$mailTemplateService = $objectManager->get(
MailTemplateService::class, $templateName, 'sg_mail', $markers
$mailTemplateService->setIgnoreMailQueue($ignoreMailQueue);
$mailTemplateService->setLanguage($GLOBALS['TSFE']->config['config']['language']);
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
$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();