Commit 4a09fb45 authored by Stefan Galinski's avatar Stefan Galinski 🎮
Browse files

[BUGFIX] Allow underscores again for the template keys in forms

parent e3e1ca97
......@@ -94,9 +94,12 @@ class FormsFinisher extends AbstractFinisher {
$templateName = $formDefinition->getIdentifier();
}
$extensionKey = trim((string) $this->parseOption('extension'));
$extensionKey = $extensionKey ?: 'sg_mail';
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$mailTemplateService = $objectManager->get(
MailTemplateService::class, $templateName, 'sg_mail', $markers
MailTemplateService::class, $templateName, $extensionKey, $markers
);
$ignoreMailQueue = (boolean) $this->parseOption('ignoreMailQueue');
......
......@@ -501,8 +501,6 @@ class MailTemplateService {
* @throws \Exception
*/
public function sendEmail($isPreview = FALSE): bool {
$registerService = GeneralUtility::makeInstance(RegisterService::class);
if (TYPO3_MODE === 'FE') {
/** @var TypoScriptFrontendController $typoscriptFrontendController */
$typoscriptFrontendController = $GLOBALS['TSFE'];
......@@ -526,6 +524,11 @@ class MailTemplateService {
}
$siteRootId = BackendService::getSiteRoot($pageUid);
$isTemplateBlacklisted = self::isTemplateBlacklisted($this->extensionKey, $this->templateName, $siteRootId);
if ($isTemplateBlacklisted) {
return TRUE;
}
/** @var Template $template */
$template = $this->templateRepository->findOneByTemplate(
$this->extensionKey, $this->templateName, $this->language, $siteRootId
......@@ -543,6 +546,7 @@ class MailTemplateService {
}
// get default template content from register array
$registerService = GeneralUtility::makeInstance(RegisterService::class);
$defaultTemplateContent =
$registerService->getRegisterArray()[$this->extensionKey][$this->templateName]['templateContent'];
......@@ -639,17 +643,13 @@ class MailTemplateService {
$this->mailMessage->setSubject($subject);
$isTemplateBlacklisted = self::isTemplateBlacklisted(
$this->extensionKey, $this->templateName, $siteRootId
);
// insert <br> tags, but replace every instance of three or more successive breaks with just two.
$emailBody = $emailView->render();
$emailBody = nl2br($emailBody);
$emailBody = preg_replace('/(<br[\s]?[\/]?>[\s]*){3,}/', '<br><br>', $emailBody);
$currentTimestamp = 0;
if ($this->ignoreMailQueue && !$isTemplateBlacklisted) {
if ($this->ignoreMailQueue) {
$this->mailMessage->setBody($emailBody, 'text/html');
$plaintextService = GeneralUtility::makeInstance(PlaintextService::class);
$plainTextBody = $plaintextService->makePlain($emailBody);
......
......@@ -138,7 +138,7 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface {
// get file name without folders
$pathAsArray = GeneralUtility::trimExplode('/', $pathToRegistrationFile);
$filename = $pathAsArray[\count($pathAsArray) - 1];
$filenameWithoutHash = GeneralUtility::trimExplode('_', $filename)[1];
$filenameWithoutHash = GeneralUtility::trimExplode('_', $filename, FALSE, 2)[1];
$hash = md5($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] . '|' . $filenameWithoutHash);
// if the filename doesn't start with the hash value, ignore it
if (strpos($filename, $hash) !== 0) {
......@@ -170,17 +170,23 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface {
private function writeRegisterArrayEntry(
$extensionKey, $templateKey, array $configArray, $insecureRegistration = FALSE
) {
// transform template directory name: your_templates => YourTemplates/
$templateDirectoryParts = GeneralUtility::trimExplode('_', $templateKey);
$templateDirectory = '';
foreach ($templateDirectoryParts as $part) {
$templateDirectory .= \ucfirst($part);
}
$templateDirectory .= '/';
// template_path means where to find the mail body content (usually it's set directly in the registration
// as template_content)
if ($configArray['template_path']) {
$templatePath = $configArray['template_path'];
} else {
if (!ExtensionManagementUtility::isLoaded($extensionKey)) {
return;
}
// transform template directory name: your_templates => YourTemplates/
$templateDirectoryParts = GeneralUtility::trimExplode('_', $templateKey);
$templateDirectory = '';
foreach ($templateDirectoryParts as $part) {
$templateDirectory .= \ucfirst($part);
}
$templateDirectory .= '/';
$templatePath = ExtensionManagementUtility::extPath($extensionKey) .
self::DEFAULT_TEMPLATE_PATH . $templateDirectory;
}
......
......@@ -92,9 +92,9 @@ class FormEditorController extends \TYPO3\CMS\Form\Controller\FormEditorControll
// the extension key doesn't needs to the necessarily the location of the configuration entry!
$extensionKey = (string) $finisher['options']['extension'];
$extensionKey = $extensionKey ?: 'sg_mail';
$templateKey = str_replace('_', '-', $finisher['options']['template']);
// if no template key was explicitly set, use the form identifier as template key
$templateKey = $finisher['options']['template'];
if ($templateKey === '') {
$templateKey = $formDefinition['identifier'] . '-' . $finisher['identifier'];
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment