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

[TASK] Initial creation of new finisher, wip

parent 40b884e3
No related branches found
Tags 4.0.20
1 merge request!7Featture forms integration
<?php
declare(strict_types=1);
namespace SGalinski\SgMail\Finisher\Forms;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use SGalinski\SgMail\Service\MailTemplateService;
use TYPO3\CMS\Core\Mail\MailMessage;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
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\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
*
* (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!
***************************************************************/
/**
* This finisher sends an email to one recipient
*
* Options:
*
* - templatePathAndFilename (mandatory): Template path and filename for the mail body
* - layoutRootPath: root path for the layouts
* - partialRootPath: root path for the partials
* - variables: associative array of variables which are available inside the Fluid template
*
* The following options control the mail sending. In all of them, placeholders in the form
* of {...} are replaced with the corresponding form value; i.e. {email} as recipientAddress
* makes the recipient address configurable.
*
* - subject (mandatory): Subject of the email
* - recipientAddress (mandatory): Email address of the recipient
* - recipientName: Human-readable name of the recipient
* - senderAddress (mandatory): Email address of the sender
* - senderName: Human-readable name of the sender
* - replyToAddress: Email address of to be used as reply-to email (use multiple addresses with an array)
* - carbonCopyAddress: Email address of the copy recipient (use multiple addresses with an array)
* - blindCarbonCopyAddress: Email address of the blind copy recipient (use multiple addresses with an array)
* - format: format of the email (one of the FORMAT_* constants). By default mails are sent as HTML
*
* Scope: frontend
*/
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
*
* @see AbstractFinisher::execute()
*
* @throws \InvalidArgumentException
* @throws FinisherException
*/
protected function executeInternal() {
$formValues = $this->finisherContext->getFormValues();
$formRuntime = $this->finisherContext->getFormRuntime();
debug($formRuntime);
debug($formValues);
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var \SGalinski\SgMail\Service\MailTemplateService $mailTemplateService */
$mailTemplateService = $objectManager->get(MailTemplateService::class);
// parse options
$extensionKey = $this->parseOption('extensionKey');
$templateName = $this->parseOption('templateName');
$recipientAddress = $this->parseOption('recipientAddress');
$senderAddress = $this->parseOption('senderAddress');
$senderName = $this->parseOption('senderName');
$mailTemplateService->setExtensionKey($extensionKey);
$mailTemplateService->setTemplateName($templateName);
$mailTemplateService->setToAddresses($recipientAddress);
$mailTemplateService->setFromAddress($senderAddress);
$mailTemplateService->setFromName($senderName);
$mailTemplateService->setLanguage($GLOBALS['TSFE']->config['config']['language']);
}
}
......@@ -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,15 @@ module.tx_sgmail {
templateDefaultLanguage = en
}
}
# frontend configuration for ext:forms
plugin.tx_form.settings.yamlConfigurations {
1499086867 = EXT:sg_mail/Configuration/Yaml/Forms/FormEngineSetup.yaml
}
# Backend configuration for ext:forms
debug = 1
module.tx_form.settings.yamlConfigurations {
1499086867 = EXT:sg_mail/Configuration/Yaml/Forms/FormEditorSetup.yaml
1499088215 = EXT:sg_mail/Configuration/Yaml/Forms/FormEngineSetup.yaml
}
\ No newline at end of file
TYPO3:
CMS:
Form:
prototypes:
standard:
formElementsDefinition:
Form:
formEditor:
editors:
900:
# Extend the finisher dropdown in the menu
selectOptions:
35:
value: 'SgMailFinisher'
label: 'SgMail Finisher'
propertyCollections:
finishers:
# define the finishers field
25:
identifier: 'SgMailFinisher'
editors:
__inheritances:
10: 'TYPO3.CMS.Form.mixins.formElementMixins.BaseCollectionEditorsMixin'
100:
label: "SgMail - E-Mail to sender(form submitter)"
110:
identifier: 'extensionKey'
templateName: 'Inspector-TextEditor'
label: 'Extension key'
propertyPath: 'options.extensionKey'
propertyValidators:
10: 'NotEmpty'
140:
identifier: 'templateName'
templateName: 'Inspector-TextEditor'
label: 'Template name'
propertyPath: 'options.templateName'
# enableFormelementSelectionButton: true
propertyValidators:
10: 'NotEmpty'
# 20: 'FormElementIdentifierWithinCurlyBracesInclusive'
# Hier ist definiert welche optionen das javascript im backend beim hinzufügen lädt.
# Am besten sollten es die selben sein wie in finisher.
finishersDefinition:
SgMailFinisher:
formEditor:
iconIdentifier: 't3-form-icon-finisher'
label: 'A Label that seems to be never used...'
predefinedDefaults:
options:
apiKey: ''
email: ''
\ No newline at end of file
TYPO3:
CMS:
Form:
prototypes:
standard:
finishersDefinition:
FormsFinisher:
FormEngine:
label: "When is this label used? And for what?"
elements:
extensionKey: {label: extensionKey, config: {type: input}}
templateName: {label: templateName , config: {type: input}}
\ 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