Commit 95166c49 authored by Torsten Oppermann's avatar Torsten Oppermann
Browse files

[TASK] Adding Hook into formhandler

parent c208a432
......@@ -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
Please register or sign in to reply
* @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
......
  • Das macht doch gar keinen Sinn den MailService als Hook für Formhandler zu missbrauchen. Was ist der Beweggrund hinter dieser Entscheidung? Bitte stets sauberen Code schreiben. So ist das ein Hack.

  • Die from-Address sollte global konfigurierbar sein per TypoScript. Das macht dann deutlich mehr Sinn. Generell ist es zudem unmöglich einen Default-Parameter zu setzen, wenn danach Pflichtparameter kommen. An sich sollte das PHP mit einer fetten SyntaxException quittieren.

  • Der Subject muss übrigens auch noch irgendwie bearbeitbar sein. Den Punkt haben wir bisher komplett vergessen. Eventuell auch einfach als extra Fluid-Template? So sicher bin ich mir da aktuell nicht. Wenn du da eine gute Idee hast, her damit. :-)

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