Skip to content
Snippets Groups Projects
Commit a7cd0aa8 authored by Stefan Galinski's avatar Stefan Galinski :video_game:
Browse files

Merge branch 'featture_forms_integration' into 'master'

Featture forms integration

See merge request !7
parents 40b884e3 5fbacdd1
No related branches found
No related tags found
1 merge request!7Featture forms integration
<?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();
}
}
......@@ -96,6 +96,11 @@ class MailTemplateService {
*/
private $templateName;
/**
* @var string $subject
*/
private $subject;
/**
* @var string $extensionKey
*/
......@@ -323,16 +328,22 @@ class MailTemplateService {
if (NULL === $defaultTemplateContent) {
$emailView->setTemplateSource($template->getContent());
$subject = $template->getSubject();
$subject = trim($template->getSubject());
} else {
$emailView->setTemplateSource($defaultTemplateContent);
$subject = self::getRegisterArray()[$this->extensionKey][$this->templateName]['subject'];
if (is_array($subject)) {
$subject = self::getRegisterArray(
)[$this->extensionKey][$this->templateName]['subject'][$this->language];
$subject = trim(
self::getRegisterArray()[$this->extensionKey][$this->templateName]['subject'][$this->language]
);
}
}
if ($this->subject !== '' && $this->subject !== NULL) {
$subject = $this->subject;
}
$this->mailMessage->setSubject($subject);
$emailView->assignMultiple($this->markers);
......@@ -763,4 +774,18 @@ class MailTemplateService {
return TRUE;
}
/**
* @return string
*/
public function getSubject(): string {
return $this->subject;
}
/**
* @param string $subject
*/
public function setSubject(string $subject) {
$this->subject = $subject;
}
}
......@@ -4,4 +4,4 @@ plugin.tx_sgmail {
partialRootPath = EXT:sg_mail/Resources/Private/Partials/
layoutRootPath = EXT:sg_mail/Resources/Private/Layouts/
}
}
}
\ No newline at end of file
......@@ -21,3 +21,13 @@ module.tx_sgmail {
templateDefaultLanguage = en
}
}
# frontend configuration for ext:forms
plugin.tx_form.settings.yamlConfigurations {
1499086546 = EXT:sg_mail/Configuration/Yaml/Forms/FinisherSetupFE.yaml
}
# Backend configuration for ext:forms
module.tx_form.settings.yamlConfigurations {
1499086546 = EXT:sg_mail/Configuration/Yaml/Forms/FinisherSetupBE.yaml
}
TYPO3:
CMS:
Form:
prototypes:
standard:
finishersDefinition:
MailToSenderFinisher:
implementationClassName: SGalinski\SgMail\Finisher\Forms\FormsFinisher
formEditor:
iconIdentifier: 't3-form-icon-finisher'
label: 'A Label that seems to be never used...'
predefinedDefaults:
options:
extension: 'sg_mail'
template: 'contact_user'
mailTo: ''
subject: ''
userName: ''
replyTo: ''
cc: ''
bcc: ''
MailToReceiverFinisher:
implementationClassName: SGalinski\SgMail\Finisher\Forms\FormsFinisher
formEditor:
iconIdentifier: 't3-form-icon-finisher'
label: 'A Label that seems to be never used...'
predefinedDefaults:
options:
extension: 'sg_mail'
template: 'contact_admin'
mailTo: ''
mailFrom: ''
subject: ''
userName: ''
replyTo: ''
cc: ''
bcc: ''
formElementsDefinition:
Form:
formEditor:
editors:
900:
# Extend the finisher dropdown in the menu
selectOptions:
25:
value: 'MailToSenderFinisher'
label: 'Mail Templates - Mail to the website user'
35:
value: 'MailToReceiverFinisher'
label: 'Mail Templates - E-Mail to the website admin'
propertyCollections:
finishers:
# define the finishers field
25:
identifier: 'MailToSenderFinisher'
editors:
__inheritances:
10: 'TYPO3.CMS.Form.mixins.formElementMixins.BaseCollectionEditorsMixin'
100:
label: "Mail Templates - E-Mail to the website user"
110:
identifier: 'extension'
templateName: 'Inspector-TextEditor'
label: 'Extension key'
propertyPath: 'options.extension'
120:
identifier: 'template'
templateName: 'Inspector-TextEditor'
label: 'Unique Template name'
propertyPath: 'options.template'
enableFormelementSelectionButton: true
130:
identifier: 'mailTo'
templateName: 'Inspector-TextEditor'
label: 'The email address of the website user'
propertyPath: 'options.mailTo'
enableFormelementSelectionButton: true
propertyValidators:
10: 'NotEmpty'
20: 'FormElementIdentifierWithinCurlyBracesInclusive'
140:
identifier: 'mailFrom'
templateName: 'Inspector-TextEditor'
label: 'The email address of the website'
propertyPath: 'options.mailFrom'
150:
identifier: 'subject'
templateName: 'Inspector-TextEditor'
label: 'The subject of the E-Mail'
propertyPath: 'options.subject'
160:
identifier: 'userName'
templateName: 'Inspector-TextEditor'
label: 'The name of the website user'
propertyPath: 'options.userName'
enableFormelementSelectionButton: true
propertyValidators:
10: 'NotEmpty'
20: 'FormElementIdentifierWithinCurlyBracesInclusive'
170:
identifier: 'replyTo'
templateName: 'Inspector-TextEditor'
label: 'The reply to address of the E-Mail'
propertyPath: 'options.replyTo'
180:
identifier: 'cc'
templateName: 'Inspector-TextEditor'
label: 'The cc address of the E-Mail'
propertyPath: 'options.cc'
190:
identifier: 'bcc'
templateName: 'Inspector-TextEditor'
label: 'The bcc address of the E-Mail'
propertyPath: 'options.bcc'
35:
identifier: 'MailToReceiverFinisher'
editors:
__inheritances:
10: 'TYPO3.CMS.Form.mixins.formElementMixins.BaseCollectionEditorsMixin'
100:
label: "Mail Templates - E-Mail to the website admin"
110:
identifier: 'extension'
templateName: 'Inspector-TextEditor'
label: 'Extension key'
propertyPath: 'options.extension'
120:
identifier: 'template'
templateName: 'Inspector-TextEditor'
label: 'Template key'
propertyPath: 'options.template'
enableFormelementSelectionButton: true
130:
identifier: 'mailTo'
templateName: 'Inspector-TextEditor'
label: 'The email address of the website admin'
propertyPath: 'options.mailTo'
140:
identifier: 'mailFrom'
templateName: 'Inspector-TextEditor'
label: 'The email address of the website'
propertyPath: 'options.mailFrom'
150:
identifier: 'subject'
templateName: 'Inspector-TextEditor'
label: 'The subject of the E-Mail'
propertyPath: 'options.subject'
160:
identifier: 'replyTo'
templateName: 'Inspector-TextEditor'
label: 'The "reply to" address of the E-Mail'
propertyPath: 'options.replyTo'
180:
identifier: 'cc'
templateName: 'Inspector-TextEditor'
label: 'The cc address of the E-Mail'
propertyPath: 'options.cc'
190:
identifier: 'bcc'
templateName: 'Inspector-TextEditor'
label: 'The bcc address of the E-Mail'
propertyPath: 'options.bcc'
renderingOptions:
translation:
translationFile:
90: 'EXT:project_theme/Resources/Private/Language/forms.xlf'
\ No newline at end of file
TYPO3:
CMS:
Form:
prototypes:
standard:
finishersDefinition:
MailToSenderFinisher:
implementationClassName: SGalinski\SgMail\Finisher\Forms\FormsFinisher
MailToReceiverFinisher:
implementationClassName: SGalinski\SgMail\Finisher\Forms\FormsFinisher
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment