From 95166c4910a7d7395ae750bfebfa801e898050e7 Mon Sep 17 00:00:00 2001 From: Torsten Oppermann <torsten@sgalinski.de> Date: Wed, 21 Sep 2016 00:25:47 +0200 Subject: [PATCH] [TASK] Adding Hook into formhandler --- Classes/Service/MailTemplateService.php | 46 ++++++++++++++++++++----- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/Classes/Service/MailTemplateService.php b/Classes/Service/MailTemplateService.php index f261e362..10744a6f 100644 --- a/Classes/Service/MailTemplateService.php +++ b/Classes/Service/MailTemplateService.php @@ -8,6 +8,8 @@ use TYPO3\CMS\Core\Mail\MailMessage; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Object\ObjectManager; use TYPO3\CMS\Fluid\View\StandaloneView; +use TYPO3\CMS\Lang\LanguageService; +use Typoheads\Formhandler\Finisher\AbstractFinisher; /*************************************************************** * Copyright notice @@ -36,7 +38,7 @@ use TYPO3\CMS\Fluid\View\StandaloneView; /** * MailTemplateService */ -class MailTemplateService { +class MailTemplateService extends AbstractFinisher { /** * @var array @@ -44,17 +46,44 @@ class MailTemplateService { private static $registerArray = []; /** - * Hook into Formhandler + * Hook into Formhandler, sets config and form input * gets called in the finisher of the typoscript + * redirects to process() function * - * @param $gp + * @param $formInput * @param $tsConfig */ - public function init($gp, $tsConfig) { + public function init($formInput, $tsConfig) { + $this->gp = $formInput; + foreach ($formInput as &$userInput) { + GeneralUtility::removeXSS($userInput); + } + + $this->tsConfig = $tsConfig; + } + + /** + * Redirect Formhandler input to send Email Function + * Needed to hook into Formhandler + */ + public function process() { + /** @var $translator LanguageService */ + $translator = (TYPO3_MODE === 'FE' ? $GLOBALS['TSFE'] : $GLOBALS['LANG']); + $subject = $translator->sL($this->tsConfig['subject'], TRUE); + self::sendEmail( - NULL, $tsConfig['template_key'], $tsConfig['extension_key'], $tsConfig['to_address'], - $tsConfig['from_address'], $tsConfig['subject'], $gp, $tsConfig['ignore_mail_queue'] + 'en', $this->tsConfig['template_key'], $this->tsConfig['extension_key'], $this->tsConfig['to_address'], + $this->tsConfig['from_address'], $subject, $this->gp, $this->tsConfig['ignore_mail_queue'] ); + return $this->gp; + } + + /** + * Needed to hook into Formhandler + * simply returns true + */ + public function validateConfig() { + parent::validateConfig(); } /** @@ -69,7 +98,7 @@ class MailTemplateService { */ public static function registerTemplate($extension, $templateName, $templatePath, $description, array $marker) { - MailTemplateService::$registerArray[$extension][$extension . '_' . $templateName] = [ + MailTemplateService::$registerArray[$extension][$templateName] = [ 'templatePath' => $templatePath, 'description' => $description, 'marker' => $marker, @@ -106,7 +135,8 @@ class MailTemplateService { * @param boolean $ignoreMailQueue */ public static function sendEmail( - $language = 'en', $templateKey, $extensionKey, $toAddress, $fromAddress, $subject, array $content = [], + $language, $templateKey, $extensionKey, $toAddress, $fromAddress = 'test@info.de', $subject, + array $content = [], $ignoreMailQueue = FALSE ) { // Set Email Content -- GitLab