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

[TASK] Code review

parent f3d4f05b
No related branches found
No related tags found
1 merge request!10Feature improved usability
......@@ -33,12 +33,14 @@ use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher;
/**
* This finisher sends an email to one recipient
* This finisher sends an email via sg_mail after form submission and enables customization of mail markers
*/
class FormsFinisher extends AbstractFinisher {
/**
* Executes this finisher
*
* Send email with the sgmail api to one or more recipients
* overwrites the mail markers with custom identifiers if provided
*
* @see AbstractFinisher::execute()
*
......@@ -49,7 +51,19 @@ class FormsFinisher extends AbstractFinisher {
*/
protected function executeInternal() {
$formValues = $this->finisherContext->getFormValues();
$formDefinition = $this->finisherContext->getFormRuntime()->getFormDefinition();
$formRuntime = $this->finisherContext->getFormRuntime();
// check if all the necessary objects exist
if ($formRuntime !== NULL) {
$formDefinition = $formRuntime->getFormDefinition();
} else {
return;
}
if ($formRuntime === NULL) {
return;
}
$markers = [];
foreach ($formValues as $identifier => $value) {
$formElement = $formDefinition->getElementByIdentifier($identifier);
......
......@@ -297,17 +297,12 @@ class MailTemplateService {
if (file_exists($defaultTemplateFile)) {
$defaultTemplateContent = file_get_contents($defaultTemplateFile);
} else {
if (isset(self::getRegisterArray()[$this->extensionKey][$this->templateName]['templateContent'])) {
$defaultTemplateContent = self::getRegisterArray(
)[$this->extensionKey][$this->templateName]['templateContent'];
// use configured default html template
$defaultTemplateFile = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultHtmlTemplate'];
if (file_exists($defaultTemplateFile)) {
$defaultTemplateContent = file_get_contents($defaultTemplateFile);
} else {
$defaultTemplateFile = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultHtmlTemplate'];
if (file_exists($defaultTemplateFile)) {
$defaultTemplateContent = file_get_contents($defaultTemplateFile);
} else {
return FALSE;
}
return FALSE;
}
}
} elseif (filter_var($template->getToAddress(), FILTER_VALIDATE_EMAIL)) {
......@@ -343,7 +338,7 @@ class MailTemplateService {
/** @var StandaloneView $emailView */
$emailView = $this->objectManager->get(StandaloneView::class);
$emailView->assignMultiple($this->markers);
$emailView->assign('all_marker', $this->getAllMarker($this->markers));
$emailView->assign('all_fields', $this->getAllMarker($this->markers));
if (NULL === $defaultTemplateContent) {
$emailView->setTemplateSource(\trim($template->getSubject()));
......@@ -876,8 +871,7 @@ class MailTemplateService {
'marker' => $marker,
'extension' => $extensionKey,
'templateName' => $templateKey,
'subject' => $subject,
'templateContent' => $configArray['templateContent']
'subject' => $subject
];
return $registerArray;
......@@ -935,11 +929,8 @@ class MailTemplateService {
$allMarker .= $key . ': ' . $innerValue . PHP_EOL;
}
} elseif (\is_bool($value)) {
if ($value) {
$allMarker .= $key . ': TRUE' . PHP_EOL;
} else {
$allMarker .= $key . ': FALSE' . PHP_EOL;
}
$valueAsString = $value ? 'true' : 'false';
$allMarker .= $key . ': ' . $valueAsString . PHP_EOL;
} elseif (\is_object($value)) {
if (method_exists($value, '__toString')) {
$allMarker .= $key . ': ' . $value->__toString() . PHP_EOL;
......
......@@ -5,7 +5,7 @@ namespace SGalinski\SgMail\XClass\Form;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (http://www.sgalinski.de)
* (c) sgalinski Internet Services (https://www.sgalinski.de)
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
......@@ -36,7 +36,7 @@ use TYPO3\CMS\Form\Type\FormDefinitionArray;
/** @noinspection LongInheritanceChainInspection */
/**
* XClass for the form editor controller in ext:form
* Displays the form editor. Enables hooking into the save process of the form to handle automatic sg mail registration
*/
class FormEditorController extends \TYPO3\CMS\Form\Controller\FormEditorController {
......@@ -144,6 +144,8 @@ class FormEditorController extends \TYPO3\CMS\Form\Controller\FormEditorControll
}
/**
* Builds the register array and saves it to the configured location
*
* @param array $renderables
* @param string $extensionKey
* @param string $templateKey
......@@ -155,10 +157,9 @@ class FormEditorController extends \TYPO3\CMS\Form\Controller\FormEditorControll
$registerFolder = GeneralUtility::getFileAbsFileName(
$configurationLocation
);
// create folder if it does not exist
if (!is_dir($registerFolder) && !mkdir($registerFolder) && !is_dir($registerFolder)) {
throw new \RuntimeException(sprintf('Directory "%s" was not created', $registerFolder));
}
// create folder
GeneralUtility::mkdir($registerFolder);
$registerFile = GeneralUtility::getFileAbsFileName(
$registerFolder . '/' . $templateKey . '.php'
);
......@@ -169,8 +170,7 @@ class FormEditorController extends \TYPO3\CMS\Form\Controller\FormEditorControll
'template_key' => $templateKey,
'description' => $templateKey,
'subject' => $templateKey,
'markers' => [],
'templateContent' => '{all_marker}'
'markers' => []
];
// add the markers for this template
......
......@@ -16,11 +16,11 @@ module.tx_sgmail {
# comma-separated list of additional cc addresses
default.cc =
# extension where automatic generated registrations from forms are put. gets appended with /Configuration/MailTemplates/. make sure these folders exist!
# extension where automatic generated registrations are put. Will be appended with /Configuration/MailTemplates/. Make sure these folders exist!
configurationLocation = project_theme
# default html template file, which serves as a fallback for all mail templates
defaultHtmlTemplate = EXT:project_theme/Configuration/MailTemplates/Default.html
defaultHtmlTemplate = EXT:sg_mail/Configuration/MailTemplates/Default.html
}
# default template language
......
......@@ -78,7 +78,7 @@ TYPO3:
127:
identifier: 'ignoreMailQueue'
templateName: 'Inspector-CheckboxEditor'
label: 'If selected, the mails are send immediately, otherwise the mails are added to the Mail Queue. See the Readme of the sg_mail extension for more Informations.'
label: 'If selected, the mails are send immediately, otherwise the mails are added to the Mail Queue. See the Readme of the sg_mail extension for more Information.'
propertyPath: 'options.ignoreMailQueue'
130:
identifier: 'mailTo'
......@@ -142,7 +142,7 @@ TYPO3:
127:
identifier: 'ignoreMailQueue'
templateName: 'Inspector-CheckboxEditor'
label: 'If selected, the mails are send immediately, otherwise the mails are added to the Mail Queue. See the Readme of the sg_mail extension for more Informations.'
label: 'If selected, the mails are send immediately, otherwise the mails are added to the Mail Queue. See the Readme of the sg_mail extension for more Information.'
propertyPath: 'options.ignoreMailQueue'
130:
identifier: 'mailTo'
......
......@@ -312,10 +312,11 @@ sg_mail comes with two new finisher for your forms with the following settings r
#### Automatic Registration
If you select to automatically register your forms with sg_mail, the default html template for the emails will be used.
You can customize the TypoScript settings in the **setup.ts** in order to have control over automatically generated registration files:
# extension where automatic generated registrations from forms are put. gets appended with /Configuration/MailTemplates/. make sure these folders exist!
# extension where automatic generated registrations are put. Will be appended with /Configuration/MailTemplates/. Make sure these folders exist!
configurationLocation = your_extension_key
# default html template file, which serves as a fallback for all mail templates
......
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