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

[BUGFIX] Fix the broken functionality for registering own templates, Simplified the content a lot

parent 3f36c7b8
No related branches found
No related tags found
No related merge requests found
......@@ -96,7 +96,7 @@ class FormsFinisher extends AbstractFinisher {
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$mailTemplateService = $objectManager->get(
MailTemplateService::class, $templateName, 'project_theme', $markers
MailTemplateService::class, $templateName, 'sg_mail', $markers
);
$ignoreMailQueue = (boolean) $this->parseOption('ignoreMailQueue');
......
......@@ -543,14 +543,14 @@ class MailTemplateService {
}
// get default template content from register array
$defaultTemplateContent = $registerService->getRegisterArray()
[$this->extensionKey][$this->templateName]['templateContent'];
$defaultTemplateContent =
$registerService->getRegisterArray()[$this->extensionKey][$this->templateName]['templateContent'];
// If there is no template for this language, use the default template
if ($template === NULL) {
if ($defaultTemplateContent === NULL) {
$templatePath = $registerService->getRegisterArray()
[$this->extensionKey][$this->templateName]['templatePath'];
$templatePath =
$registerService->getRegisterArray()[$this->extensionKey][$this->templateName]['templatePath'];
// only standard template file is considered since version 4.1
$defaultTemplateFile = $templatePath . 'template.html';
......
......@@ -244,16 +244,18 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface {
* @param array $markers
* @param string $subject
* @param string $description
* @return string
*/
public function writeRegisterFile($templateKey, $extensionKey, $markers, $subject, $description) {
// get the location where registrations should be stored
public function writeRegisterFile($templateKey, $extensionKey, $markers, $subject = '', $description = ''): string {
$configurationLocation = $this->getRegistrationPath();
$registerFolder = GeneralUtility::getFileAbsFileName($configurationLocation);
GeneralUtility::mkdir_deep($registerFolder);
$registerFile = GeneralUtility::getFileAbsFileName($registerFolder . '/' . $templateKey . '.php');
// build the register array
$hashPrefix = md5($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] . '|' . $templateKey . '.php');
$registerFile = GeneralUtility::getFileAbsFileName(
$registerFolder . '/' . $hashPrefix . '_' . $templateKey . '.php'
);
$newRegisterArray = [
'extension_key' => $extensionKey,
'template_key' => $templateKey,
......@@ -262,7 +264,6 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface {
'markers' => []
];
// add the markers for this template
foreach ($markers as $marker) {
$markerName = $marker['identifier'];
$newRegisterArray['markers'][] = [
......@@ -274,5 +275,7 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface {
}
file_put_contents($registerFile, '<?php return ' . var_export($newRegisterArray, TRUE) . ';');
return $registerFile;
}
}
......@@ -27,7 +27,6 @@ namespace SGalinski\SgMail\XClass\Form;
use SGalinski\SgMail\Service\MailTemplateService;
use SGalinski\SgMail\Service\RegisterService;
use SGalinski\SgMail\Service\TypoScriptSettingsService;
use Symfony\Component\Yaml\Yaml;
use TYPO3\CMS\Core\Resource\ResourceStorage;
use TYPO3\CMS\Core\Resource\StorageRepository;
......@@ -90,8 +89,9 @@ class FormEditorController extends \TYPO3\CMS\Form\Controller\FormEditorControll
}
// retrieve the extension and template key and jump out of loop
// the extension key doesn't needs to the necessarily the location of the configuration entry!
$extensionKey = (string) $finisher['options']['extension'];
$extensionKey = $extensionKey ?: 'project_theme';
$extensionKey = $extensionKey ?: 'sg_mail';
$templateKey = str_replace('_', '-', $finisher['options']['template']);
// if no template key was explicitly set, use the form identifier as template key
......@@ -161,26 +161,7 @@ class FormEditorController extends \TYPO3\CMS\Form\Controller\FormEditorControll
* @return string
*/
private function writeRegisterFile(array $renderables, $extensionKey, $templateKey): string {
// get the location where automatic registrations should be stored
$configurationLocation = $this->getRegistrationPath();
$registerFolder = GeneralUtility::getFileAbsFileName($configurationLocation);
GeneralUtility::mkdir_deep($registerFolder);
$hashPrefix = md5($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] . '|' . $templateKey . '.php');
$registerFile = GeneralUtility::getFileAbsFileName(
$registerFolder . '/' . $hashPrefix . '_' . $templateKey . '.php'
);
// build the register array
$newRegisterArray = [
'extension_key' => $extensionKey,
'template_key' => $templateKey,
'description' => $templateKey,
'subject' => $templateKey,
'markers' => []
];
// add the markers for this template
$markers = [];
foreach ($renderables as $element) {
// if markerName is explicitly set, override the registered identifier
$markerName = $element['identifier'];
......@@ -188,7 +169,7 @@ class FormEditorController extends \TYPO3\CMS\Form\Controller\FormEditorControll
$markerName = $element['properties']['markerName'];
}
$newRegisterArray['markers'][] = [
$markers[] = [
'marker' => $markerName,
'type' => MailTemplateService::MARKER_TYPE_STRING,
'value' => $element['label'],
......@@ -196,23 +177,7 @@ class FormEditorController extends \TYPO3\CMS\Form\Controller\FormEditorControll
];
}
file_put_contents($registerFile, '<?php return ' . var_export($newRegisterArray, TRUE) . ';');
return $registerFile;
}
/**
* Returns the path to the configured location where automatic mail template registrations should be
*
* @return string
*/
private function getRegistrationPath(): string {
// get typoscript settings from sg mail
/** @var TypoScriptSettingsService $typoScriptSettingsService */
$typoScriptSettingsService = $this->objectManager->get(TypoScriptSettingsService::class);
$tsSettings = $typoScriptSettingsService->getSettings(0, 'tx_sgmail');
// get the location where automatic registrations should be stored
return 'EXT:' . $tsSettings['mail']['configurationLocation'] . '/' . RegisterService::CONFIG_PATH;
$registrationService = $this->objectManager->get(RegisterService::class);
return $registrationService->writeRegisterFile($templateKey, $extensionKey, $markers, $templateKey);
}
}
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