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

[TASK] Refactored registration functions, moved them to a dedicated service.

parent 836af9dc
No related branches found
No related tags found
1 merge request!11Feature security update
......@@ -28,6 +28,7 @@ namespace SGalinski\SgMail\Service;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
......@@ -91,10 +92,89 @@ class RegisterService implements \TYPO3\CMS\Core\SingletonInterface {
}
/**
*
* Read every registered file and create a registration entry in the registerArray if possible
*/
private function registerExtensions() {
foreach ($this->registrationFiles as $registerFile) {
// clear registerArray
$registerArray = [];
if (\is_file($registerFile)) {
$configArray = (include $registerFile);
$extensionKey = $configArray['extension_key'];
$templateKey = $configArray['template_key'];
if ($extensionKey === NULL || $templateKey === NULL) {
continue;
}
$registerArray = $this->writeRegisterArrayEntry(
$registerArray, $extensionKey, $templateKey, $configArray
);
}
// set the register array after every registration has been parsed
$this->registerArray = $registerArray;
}
}
/**
* write a single entry into the register array
*
* @param array $registerArray
* @param $extensionKey
* @param $templateKey
* @param array $configArray
* @param bool $transformTemplateFolder
* @param string $storeTemplateExtension
* @return array
*/
private function writeRegisterArrayEntry(
array $registerArray, $extensionKey, $templateKey, array $configArray,
$transformTemplateFolder = TRUE, $storeTemplateExtension = ''
): array {
// If it is not explicitly set in which extension the html should be located, use the extension set in the template settings
if ($storeTemplateExtension === '') {
$storeTemplateExtension = $extensionKey;
}
// give the option to use the template key as folder name. this is used mainly with auto registering
$templateDirectory = $templateKey;
// by default folders with underscore will be transformed to upper camelcase
if ($transformTemplateFolder) {
// transform template directory name: your_templates => YourTemplates/
$templateDirectoryParts = GeneralUtility::trimExplode('_', $templateKey);
$templateDirectory = '';
foreach ($templateDirectoryParts as $part) {
$templateDirectory .= ucfirst($part);
}
}
$templateDirectory .= '/';
$templatePath = ExtensionManagementUtility::extPath($storeTemplateExtension) . self::DEFAULT_TEMPLATE_PATH
. $templateDirectory;
if ($configArray['template_path']) {
$templatePath = $configArray[$templateKey];
}
$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;
}
}
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