Skip to content
Snippets Groups Projects
Commit b9f6760a authored by Torsten Oppermann's avatar Torsten Oppermann
Browse files

[TASK] WIP - Finishing forms integration

parent 315033d9
No related branches found
No related tags found
1 merge request!7Featture forms integration
Showing
with 423 additions and 70 deletions
...@@ -17,17 +17,9 @@ namespace SGalinski\SgMail\Finisher\Forms; ...@@ -17,17 +17,9 @@ namespace SGalinski\SgMail\Finisher\Forms;
*/ */
use SGalinski\SgMail\Service\MailTemplateService; use SGalinski\SgMail\Service\MailTemplateService;
use TYPO3\CMS\Core\Mail\MailMessage;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
use TYPO3\CMS\Extbase\Object\ObjectManager; use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher; use TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher;
use TYPO3\CMS\Form\Domain\Finishers\Exception\FinisherException;
use TYPO3\CMS\Form\Domain\Model\FormElements\FileUpload;
use TYPO3\CMS\Form\Domain\Runtime\FormRuntime;
use TYPO3\CMS\Form\Service\TranslationService;
use TYPO3\CMS\Form\ViewHelpers\RenderRenderableViewHelper;
/*************************************************************** /***************************************************************
* Copyright notice * Copyright notice
...@@ -80,18 +72,6 @@ use TYPO3\CMS\Form\ViewHelpers\RenderRenderableViewHelper; ...@@ -80,18 +72,6 @@ use TYPO3\CMS\Form\ViewHelpers\RenderRenderableViewHelper;
* Scope: frontend * Scope: frontend
*/ */
class FormsFinisher extends AbstractFinisher { class FormsFinisher extends AbstractFinisher {
const FORMAT_PLAINTEXT = 'plaintext';
const FORMAT_HTML = 'html';
/**
* @var array
*/
protected $defaultOptions = [
'recipientName' => '',
'senderName' => '',
'format' => self::FORMAT_HTML,
'attachUploads' => TRUE
];
/** /**
* Executes this finisher * Executes this finisher
...@@ -99,31 +79,26 @@ class FormsFinisher extends AbstractFinisher { ...@@ -99,31 +79,26 @@ class FormsFinisher extends AbstractFinisher {
* @see AbstractFinisher::execute() * @see AbstractFinisher::execute()
* *
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* @throws FinisherException * @throws \BadFunctionCallException
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
*/ */
protected function executeInternal() { protected function executeInternal() {
$formValues = $this->finisherContext->getFormValues(); $formValues = $this->finisherContext->getFormValues();
$formRuntime = $this->finisherContext->getFormRuntime();
debug($formRuntime);
debug($formValues);
$objectManager = GeneralUtility::makeInstance(ObjectManager::class); $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var \SGalinski\SgMail\Service\MailTemplateService $mailTemplateService */ /** @var \SGalinski\SgMail\Service\MailTemplateService $mailTemplateService */
$mailTemplateService = $objectManager->get(MailTemplateService::class); $mailTemplateService = $objectManager->get(
MailTemplateService::class, $this->parseOption('template'), 'sg_mail', $formValues
);
// parse options $mailTemplateService->setIgnoreMailQueue(TRUE);
$extensionKey = $this->parseOption('extensionKey'); $mailTemplateService->setToAddresses($this->parseOption('mailTo'));
$templateName = $this->parseOption('templateName'); $mailTemplateService->setFromAddress($this->parseOption('mailFrom'));
$recipientAddress = $this->parseOption('recipientAddress'); $mailTemplateService->setFromName($this->parseOption('userName'));
$senderAddress = $this->parseOption('senderAddress'); $mailTemplateService->setReplyToAddress($this->parseOption('replyTo'));
$senderName = $this->parseOption('senderName'); $mailTemplateService->setCcAddresses($this->parseOption('cc'));
$mailTemplateService->setBccAddresses($this->parseOption('bcc'));
$mailTemplateService->setExtensionKey($extensionKey); $mailTemplateService->sendEmail();
$mailTemplateService->setTemplateName($templateName);
$mailTemplateService->setToAddresses($recipientAddress);
$mailTemplateService->setFromAddress($senderAddress);
$mailTemplateService->setFromName($senderName);
$mailTemplateService->setLanguage($GLOBALS['TSFE']->config['config']['language']);
} }
} }
<?php
/***************************************************************
* 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!
***************************************************************/
return [
'extension_key' => 'sg_mail',
'template_key' => 'template1',
'description' => 'LLL:EXT:project_theme/Resources/Private/Language/locallang.xlf:mail.contact_user.description',
'subject' => 'LLL:EXT:project_theme/Resources/Private/Language/locallang.xlf:mail.contact_user.description',
'markers' => [
[
'marker' => 'text-1',
'type' => \SGalinski\SgMail\Service\MailTemplateService::MARKER_TYPE_STRING,
'value' => 'Max Mustermann',
'description' => 'LLL:EXT:project_theme/Resources/Private/Language/locallang.xlf:mail.marker.name',
]
]
];
<?php
/***************************************************************
* 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!
***************************************************************/
return [
'extension_key' => 'sg_mail',
'template_key' => 'template2',
'description' => 'LLL:EXT:project_theme/Resources/Private/Language/locallang.xlf:mail.contact_admin.description',
'subject' => 'LLL:EXT:project_theme/Resources/Private/Language/locallang.xlf:mail.contact_admin.description',
'markers' => [
[
'marker' => 'text-1',
'type' => \SGalinski\SgMail\Service\MailTemplateService::MARKER_TYPE_STRING,
'value' => 'Max Mustermann',
'description' => 'LLL:EXT:project_theme/Resources/Private/Language/locallang.xlf:mail.marker.name',
]
]
];
...@@ -24,12 +24,13 @@ module.tx_sgmail { ...@@ -24,12 +24,13 @@ module.tx_sgmail {
# frontend configuration for ext:forms # frontend configuration for ext:forms
plugin.tx_form.settings.yamlConfigurations { plugin.tx_form.settings.yamlConfigurations {
1499086547 = EXT:sg_mail/Configuration/Yaml/Forms/BaseSetup.yaml
1499086867 = EXT:sg_mail/Configuration/Yaml/Forms/FormEngineSetup.yaml 1499086867 = EXT:sg_mail/Configuration/Yaml/Forms/FormEngineSetup.yaml
} }
# Backend configuration for ext:forms # Backend configuration for ext:forms
debug = 1
module.tx_form.settings.yamlConfigurations { module.tx_form.settings.yamlConfigurations {
1499086547 = EXT:sg_mail/Configuration/Yaml/Forms/BaseSetup.yaml
1499086867 = EXT:sg_mail/Configuration/Yaml/Forms/FormEditorSetup.yaml 1499086867 = EXT:sg_mail/Configuration/Yaml/Forms/FormEditorSetup.yaml
1499088215 = EXT:sg_mail/Configuration/Yaml/Forms/FormEngineSetup.yaml 1499088215 = EXT:sg_mail/Configuration/Yaml/Forms/FormEngineSetup.yaml
} }
\ No newline at end of file
TYPO3:
CMS:
Form:
persistenceManager:
allowedExtensionPaths:
10: EXT:sg_mail/Resources/Private/Forms/
allowSaveToExtensionPaths: true
allowDeleteFromExtensionPaths: true
prototypes:
standard:
finishersDefinition:
MailToSenderFinisher:
implementationClassName: SGalinski\SgMail\Finisher\Forms\FormsFinisher
MailToReceiverFinisher:
implementationClassName: SGalinski\SgMail\Finisher\Forms\FormsFinisher
formElementsDefinition:
Form:
renderingOptions:
templateRootPaths:
100: 'EXT:sg_mail/Resources/Private/Forms/Templates/'
partialRootPaths:
100: 'EXT:sg_mail/Resources/Private/Forms/Partials/'
layoutRootPaths:
100: 'EXT:sg_mail/Resources/Private/Forms/Layouts/'
\ No newline at end of file
...@@ -10,43 +10,170 @@ TYPO3: ...@@ -10,43 +10,170 @@ TYPO3:
900: 900:
# Extend the finisher dropdown in the menu # Extend the finisher dropdown in the menu
selectOptions: selectOptions:
25:
value: 'MailToSenderFinisher'
label: 'SgMail - Mail to Website user'
35: 35:
value: 'SgMailFinisher' value: 'MailToReceiverFinisher'
label: 'SgMail Finisher' label: 'SgMail - E-Mail to Admin'
propertyCollections: propertyCollections:
finishers: finishers:
# define the finishers field # define the finishers field
25: 25:
identifier: 'SgMailFinisher' identifier: 'MailToSenderFinisher'
editors: editors:
__inheritances: __inheritances:
10: 'TYPO3.CMS.Form.mixins.formElementMixins.BaseCollectionEditorsMixin' 10: 'TYPO3.CMS.Form.mixins.formElementMixins.BaseCollectionEditorsMixin'
100: 100:
label: "SgMail - E-Mail to sender(form submitter)" label: "SgMail - E-Mail to website user"
110: 110:
identifier: 'extensionKey' identifier: 'template'
templateName: 'Inspector-SingleSelectEditor'
label: 'Unique Template name'
propertyPath: 'options.template'
selectOptions:
0:
value: 'template1'
label: 'Template 1'
1:
value: 'template2'
label: 'Template 2'
2:
value: 'template3'
label: 'Template 3'
3:
value: 'template4'
label: 'Template 4'
4:
value: 'template5'
label: 'Template 5'
120:
identifier: 'mailTo'
templateName: 'Inspector-TextEditor' templateName: 'Inspector-TextEditor'
label: 'Extension key' label: 'The email address of the website user'
propertyPath: 'options.extensionKey' propertyPath: 'options.mailTo'
enableFormelementSelectionButton: true
propertyValidators: propertyValidators:
10: 'NotEmpty' 10: 'NotEmpty'
140: 20: 'FormElementIdentifierWithinCurlyBracesInclusive'
identifier: 'templateName' 125:
identifier: 'mailFrom'
templateName: 'Inspector-TextEditor' templateName: 'Inspector-TextEditor'
label: 'Template name' label: 'The email address of the website'
propertyPath: 'options.templateName' propertyPath: 'options.mailFrom'
# enableFormelementSelectionButton: true 160:
identifier: 'subject'
templateName: 'Inspector-TextEditor'
label: 'The Subject of the E-Mail'
propertyPath: 'options.subject'
170:
identifier: 'userName'
templateName: 'Inspector-TextEditor'
label: 'The Name of the Website user'
propertyPath: 'options.userName'
enableFormelementSelectionButton: true
propertyValidators: propertyValidators:
10: 'NotEmpty' 10: 'NotEmpty'
# 20: 'FormElementIdentifierWithinCurlyBracesInclusive' 20: 'FormElementIdentifierWithinCurlyBracesInclusive'
# Hier ist definiert welche optionen das javascript im backend beim hinzufügen lädt. 190:
# Am besten sollten es die selben sein wie in finisher. identifier: 'replyTo'
templateName: 'Inspector-TextEditor'
label: 'The reply to Address of the E-Mail'
propertyPath: 'options.replyTo'
200:
identifier: 'cc'
templateName: 'Inspector-TextEditor'
label: 'The cc Address of the E-Mail'
propertyPath: 'options.cc'
210:
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: "SgMail - E-Mail to Website Admin"
110:
identifier: 'template'
templateName: 'Inspector-SingleSelectEditor'
label: 'Unique Template name'
propertyPath: 'options.template'
selectOptions:
0:
value: 'template1'
label: 'Template 1'
1:
value: 'template2'
label: 'Template 2'
2:
value: 'template3'
label: 'Template 3'
3:
value: 'template4'
label: 'Template 4'
4:
value: 'template5'
label: 'Template 5'
120:
identifier: 'mailTo'
templateName: 'Inspector-TextEditor'
label: 'The email address of the admin'
propertyPath: 'options.mailTo'
125:
identifier: 'mailFrom'
templateName: 'Inspector-TextEditor'
label: 'The email address of the website'
propertyPath: 'options.mailFrom'
160:
identifier: 'subject'
templateName: 'Inspector-TextEditor'
label: 'The Subject of the E-Mail'
propertyPath: 'options.subject'
190:
identifier: 'replyTo'
templateName: 'Inspector-TextEditor'
label: 'The reply to Address of the E-Mail'
propertyPath: 'options.replyTo'
200:
identifier: 'cc'
templateName: 'Inspector-TextEditor'
label: 'The cc Address of the E-Mail'
propertyPath: 'options.cc'
210:
identifier: 'bcc'
templateName: 'Inspector-TextEditor'
label: 'The bcc Address of the E-Mail'
propertyPath: 'options.bcc'
# Backend options
finishersDefinition: finishersDefinition:
SgMailFinisher: MailToSenderFinisher:
formEditor:
iconIdentifier: 't3-form-icon-finisher'
label: 'A Label that seems to be never used...'
predefinedDefaults:
options:
template: 'template1'
mailTo: ''
subject: ''
userName: ''
replyTo: ''
cc: ''
bcc: ''
MailToReceiverFinisher:
formEditor: formEditor:
iconIdentifier: 't3-form-icon-finisher' iconIdentifier: 't3-form-icon-finisher'
label: 'A Label that seems to be never used...' label: 'A Label that seems to be never used...'
predefinedDefaults: predefinedDefaults:
options: options:
apiKey: '' template: 'template2'
email: '' mailTo: ''
\ No newline at end of file mailFrom: ''
subject: ''
userName: ''
replyTo: ''
cc: ''
bcc: ''
\ No newline at end of file
TYPO3: #TYPO3:
CMS: # CMS:
Form: # Form:
prototypes: # prototypes:
standard: # standard:
finishersDefinition: # finishersDefinition:
FormsFinisher: # MailToSenderFinisher:
FormEngine: # FormEngine:
label: "When is this label used? And for what?" # label: ''
elements: # elements:
extensionKey: {label: extensionKey, config: {type: input}} # format:
templateName: {label: templateName , config: {type: input}} # label: 'tt_content.finishersDefinition.EmailToSender.format.label'
\ No newline at end of file # config:
# type: select
# renderType: 'selectSingle'
# minitems: 1
# maxitems: 1
# size: 1
# items:
# 10:
# 0: 'tt_content.finishersDefinition.EmailToSender.format.1'
# 1: 'html'
# 20:
# 0: 'tt_content.finishersDefinition.EmailToSender.format.2'
# 1: 'plaintext'
\ No newline at end of file
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" xmlns:formvh="http://typo3.org/ns/TYPO3/CMS/Form/ViewHelpers" data-namespace-typo3-fluid="true">
<f:form.validationResults for="{element.rootForm.identifier}.{element.identifier}">
<div class="form-group{f:if(condition: '{validationResults.errors.0}', then: ' has-error')}">
<div class="{element.properties.containerClassAttribute}">
<f:format.raw>
{elementContent}
<f:if condition="{validationResults.flattenedErrors}">
<span class="error help-block" role="alert">
<f:for each="{validationResults.errors}" as="error">
{formvh:translateElementError(element: element, code: error.code, arguments: error.arguments, defaultValue: error.message)}
<br />
</f:for>
</span>
</f:if>
</f:format.raw>
<f:if condition="{element.properties.elementDescription}">
<span class="help-block">{formvh:translateElementProperty(element: element, property: 'elementDescription')}</span>
</f:if>
</div>
</div>
</f:form.validationResults>
</html>
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" xmlns:formvh="http://typo3.org/ns/TYPO3/CMS/Form/ViewHelpers" data-namespace-typo3-fluid="true">
<span class="required">*</span>
</html>
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" xmlns:formvh="http://typo3.org/ns/TYPO3/CMS/Form/ViewHelpers" data-namespace-typo3-fluid="true">
<formvh:renderRenderable renderable="{page}">
<f:if condition="{page.label}">
<h2>{formvh:translateElementProperty(element: page, property: 'label')}</h2>
</f:if>
<f:for each="{page.elements}" as="element">
<f:render partial="{element.templateName}" arguments="{element: element}" />
</f:for>
</formvh:renderRenderable>
</html>
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" xmlns:formvh="http://typo3.org/ns/TYPO3/CMS/Form/ViewHelpers" data-namespace-typo3-fluid="true">
<formvh:renderRenderable renderable="{element}">
<f:render partial="Field/Field" arguments="{element: element}" contentAs="elementContent">
<f:form.textfield
property="{element.identifier}"
id="{element.uniqueIdentifier}"
class="{element.properties.elementClassAttribute} form-control"
errorClass="{element.properties.elementErrorClassAttribute}"
additionalAttributes="{formvh:translateElementProperty(element: element, property: 'fluidAdditionalAttributes')}"
/>
</f:render>
</formvh:renderRenderable>
</html>
renderingOptions:
submitButtonLabel: Submit
type: Form
identifier: contactForm
label: 'Contact Form'
prototypeName: standard
finishers:
-
options:
format: html
template: template1
mailTo: '{text-2}'
subject: ''
userName: '{text-1}'
replyTo: ''
cc: ''
bcc: ''
identifier: MailToSenderFinisher
-
options:
template: template2
mailTo: admin@sgalinski.de
mailFrom: info@sgalinski.de
subject: subject2
userName: ''
replyTo: ''
cc: ''
bcc: ''
identifier: MailToReceiverFinisher
renderables:
-
renderingOptions:
previousButtonLabel: 'Previous step'
nextButtonLabel: 'Next step'
type: Page
identifier: page-1
label: Step
renderables:
-
defaultValue: ''
type: Text
identifier: text-1
label: Name
properties:
fluidAdditionalAttributes:
placeholder: Name
required: required
elementDescription: ''
validators:
-
identifier: NotEmpty
-
defaultValue: ''
type: Text
identifier: text-2
label: 'Ihre E-Mail-Adresse'
properties:
fluidAdditionalAttributes:
placeholder: 'Ihre E-Mail-Adresse'
required: required
validators:
-
identifier: NotEmpty
-
identifier: EmailAddress
-
defaultValue: ''
type: Text
identifier: text-3
label: Nachricht
properties:
fluidAdditionalAttributes:
placeholder: Nachricht
required: required
validators:
-
identifier: NotEmpty
{text-1}
Template Contact User: Template1
\ No newline at end of file
{text-1}
{text-2}
Template 2
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