diff --git a/Classes/Service/RegisterService.php b/Classes/Service/RegisterService.php index ea242236989e6fb8fd61724f92a1525f8ef1f9d1..2454d9a1c7064761f0a4d3b42b6ddba8f4ab2146 100644 --- a/Classes/Service/RegisterService.php +++ b/Classes/Service/RegisterService.php @@ -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; } }