Commit 8657ce1d authored by Torsten Oppermann's avatar Torsten Oppermann
Browse files

[TASK] Adding possibility to register multiple templates via single file + refactored some code

parent d332dc00
......@@ -59,6 +59,8 @@ class MailTemplateService {
const DEFAULT_TEMPLATE_PATH = 'Resources/Private/Templates/SgMail/';
const CACHE_NAME = 'sg_mail_registerArrayCache';
const CACHE_LIFETIME_IN_SECONDS = 86400;
const REGISTER_FILE = 'Register.php';
const CONFIG_PATH = 'Configuration/MailTemplates';
/**
* @var array $toAddresses
......@@ -788,7 +790,7 @@ class MailTemplateService {
foreach ($extensionList as $extensionName) {
$extensionConfigDirectory = ExtensionManagementUtility::extPath($extensionName);
$extensionConfigDirectory .= '/Configuration/MailTemplates';
$extensionConfigDirectory .= '/' . self::CONFIG_PATH;
$configFiles = GeneralUtility::getFilesInDir($extensionConfigDirectory);
foreach ($configFiles as $configFile) {
......@@ -796,36 +798,93 @@ class MailTemplateService {
$extensionKey = $configArray['extension_key'];
$templateKey = $configArray['template_key'];
// transform template directory name: your_templates => YourTemplates/
$templateDirectoryParts = GeneralUtility::trimExplode('_', $configArray['template_key']);
$templateDirectory = '';
foreach ($templateDirectoryParts as $part) {
$templateDirectory .= ucfirst($part);
if ($extensionKey === NULL || $templateKey === NULL) {
continue;
}
$templateDirectory .= '/';
$templatePath = ExtensionManagementUtility::extPath(
$extensionName
) . self::DEFAULT_TEMPLATE_PATH . $templateDirectory;
if ($configArray['template_path']) {
$templatePath = $configArray['template_key'];
}
$registerArray = self::writeRegisterArrayEntry(
$registerArray, $extensionName, $extensionKey, $templateKey, $configArray
);
}
}
$description = $configArray['description'];
$subject = $configArray['subject'];
$marker = $configArray['markers'];
$registerArray[$extensionKey][$templateKey] = [
'templatePath' => $templatePath,
'description' => $description,
'marker' => $marker,
'extension' => $extensionKey,
'templateName' => $templateKey,
'subject' => $subject
];
// now check for registration files with multiple templates registered
$registerArray = self::registerFromSingleFile($registerArray);
return $registerArray;
}
/**
* Find Register.php files in all installed extensions and register the templates
* These files can contain multiple template registrations and are structured as multi-dimensional arrays
*
* @param array $registerArray
* @return array
*/
private static function registerFromSingleFile(array $registerArray) {
$extensionList = ExtensionManagementUtility::getLoadedExtensionListArray();
foreach ($extensionList as $extension) {
$extensionConfigDirectory = ExtensionManagementUtility::extPath($extension);
$extensionConfigDirectory .= self::CONFIG_PATH;
if (!\is_dir($extensionConfigDirectory)) {
continue;
}
$configArray = (include $extensionConfigDirectory . '/' . self::REGISTER_FILE);
if ($configArray) {
foreach ($configArray as $config) {
$registerArray = self::writeRegisterArrayEntry($registerArray, $config['extension_key'], $config['extension_key'], $config['template_key'], $config);
}
}
}
return $registerArray;
}
/**
* writes a single entry into the register array
*
* @param array $registerArray
* @param string $extensionName
* @param string $extensionKey
* @param string $templateKey
* @param array $configArray
* @return array
*/
private static function writeRegisterArrayEntry(
array $registerArray, $extensionName, $extensionKey, $templateKey, array $configArray
) {
// transform template directory name: your_templates => YourTemplates/
$templateDirectoryParts = GeneralUtility::trimExplode('_', $configArray['template_key']);
$templateDirectory = '';
foreach ($templateDirectoryParts as $part) {
$templateDirectory .= ucfirst($part);
}
$templateDirectory .= '/';
$templatePath = ExtensionManagementUtility::extPath(
$extensionName
) . self::DEFAULT_TEMPLATE_PATH . $templateDirectory;
if ($configArray['template_path']) {
$templatePath = $configArray['template_key'];
}
$description = $configArray['description'];
$subject = $configArray['subject'];
$marker = $configArray['markers'];
$registerArray[$extensionKey][$templateKey] = [
'templatePath' => $templatePath,
'description' => $description,
'marker' => $marker,
'extension' => $extensionKey,
'templateName' => $templateKey,
'subject' => $subject
];
return $registerArray;
}
......
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