Commit 272c105f authored by Torsten Oppermann's avatar Torsten Oppermann
Browse files

[TASK] new Register function for templates

parent 30d2a028
......@@ -34,6 +34,7 @@ use SGalinski\SgMail\Domain\Repository\TemplateRepository;
use Swift_Attachment;
use Swift_OutputByteStream;
use TYPO3\CMS\Core\Mail\MailMessage;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
......@@ -150,9 +151,16 @@ class MailTemplateService {
/**
* MailTemplateService constructor.
*
* @param string $templateName
* @param string $extensionKey
* @param string $markers
* @throws \InvalidArgumentException
*/
public function __construct() {
public function __construct($templateName = '', $extensionKey = '', $markers = '') {
$this->templateName = $templateName;
$this->extensionKey = $extensionKey;
$this->markers = $markers;
/** @var ObjectManager objectManager */
$this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var MailMessage mailMessage */
......@@ -714,4 +722,60 @@ class MailTemplateService {
$this->pid = (int) $pid;
return $this;
}
/**
* Iterate over all installed extensions and look for sg_mail configuration files
* If found, register the template(s)
*
* @throws \BadFunctionCallException
*/
public static function registerExtensions() {
// clear registerArray
self::$registerArray = [];
$extensionList = ExtensionManagementUtility::getLoadedExtensionListArray();
foreach ($extensionList as $extensionName) {
$extensionConfigDirectory = ExtensionManagementUtility::extPath($extensionName);
$extensionConfigDirectory .= '/Configuration/MailTemplates';
$configFiles = GeneralUtility::getFilesInDir($extensionConfigDirectory);
foreach ($configFiles as $configFile) {
$configArray = (include $extensionConfigDirectory . '/' . $configFile);
self::registerByConfigArray($configArray, $extensionName);
}
}
}
/**
* Register a template with a config array
*
* @param array $config
* @param string $extensionName
* @throws \BadFunctionCallException
*/
private static function registerByConfigArray(array $config = [], $extensionName) {
$extensionKey = $config['extension_key'];
$templateKey = $config['template_key'];
$templatePath = ExtensionManagementUtility::extPath(
$extensionName
) . '/Resources/Private/Template/SgMail/' . ucfirst($config['template_key']);
if ($config['template_path']) {
$templatePath = $config['template_key'];
}
$description = $config['description'];
$subject = $config['subject'];
$marker = $config['markers'];
self::$registerArray[$extensionKey][$templateKey] = [
'templatePath' => $templatePath,
'description' => $description,
'marker' => $marker,
'extension' => $extensionKey,
'templateName' => $templateKey,
'subject' => $subject
];
}
}
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