Skip to content
Snippets Groups Projects

Featture forms integration

Merged Torsten Oppermann requested to merge featture_forms_integration into master
1 unresolved thread
Files
6
<?php
declare(strict_types=1);
namespace SGalinski\SgMail\Service;
namespace SGalinski\SgMail\Finisher\Forms;
/***************************************************************
* Copyright notice
@@ -26,74 +27,44 @@ namespace SGalinski\SgMail\Service;
* 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 Typoheads\Formhandler\Finisher\AbstractFinisher;
use TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher;
/**
* Class FormhandlerFinisherService
*
* @package SGalinski\SgMail\Service
* This finisher sends an email to one recipient
*/
class FormhandlerFinisherService extends AbstractFinisher {
class FormsFinisher extends AbstractFinisher {
/**
* Hook into Formhandler, sets config and form input
* gets called in the finisher of the typoscript
* redirects to process() function
* Executes this finisher
*
* @param array $formInput
* @param array $settings
*/
public function init($formInput, $settings) {
foreach ($formInput as &$userInput) {
// if value is an array, iterate over array values
if (is_array($userInput)) {
foreach ($userInput as &$input) {
$input = GeneralUtility::removeXSS($input);
}
continue;
}
$userInput = GeneralUtility::removeXSS($userInput);
}
$this->gp = $formInput;
$this->settings = $settings;
}
/**
* Redirect Formhandler input to send Email Function
* Needed to hook into Formhandler
* @see AbstractFinisher::execute()
*
* @return array $gp
* @throws \BadFunctionCallException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
* @throws \InvalidArgumentException
* @throws \BadFunctionCallException
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
*/
public function process() {
if (!isset($this->settings['to_address'])) {
$toAddressField = $this->settings['to_address_field'];
$toAddress = $this->gp[$toAddressField];
} else {
$toAddress = $this->settings['to_address'];
}
protected function executeInternal() {
$formValues = $this->finisherContext->getFormValues();
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var \SGalinski\SgMail\Service\MailTemplateService $mailTemplateService */
$mailTemplateService = $objectManager->get(MailTemplateService::class);
$mailTemplateService->setToAddresses($toAddress);
$mailTemplateService = $objectManager->get(
MailTemplateService::class, $this->parseOption('template'), $this->parseOption('extension'), $formValues
);
$mailTemplateService->setIgnoreMailQueue(FALSE);
$mailTemplateService->setLanguage($GLOBALS['TSFE']->config['config']['language']);
$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();
$mailTemplateService->setSubject($this->parseOption('subject'));
$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'));
return $this->gp;
$mailTemplateService->sendEmail();
}
}
Loading