Commit 68f6d76c authored by Torsten Oppermann's avatar Torsten Oppermann
Browse files

[TASK] Refactoring extension registration

parent 46081957
......@@ -26,7 +26,7 @@ namespace SGalinski\SgMail\Controller;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use SGalinski\SgMail\Service\MailTemplateService;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
/**
......@@ -38,7 +38,21 @@ class MailController extends ActionController {
*
*/
public function indexAction() {
$this->view->assign('extensions', MailTemplateService::$registerArray);
$path = ExtensionManagementUtility::extPath(
Please register or sign in to reply
'sg_mail'
) . 'Configuration/Templates/';
$results = scandir($path);
$extensions = [];
foreach ($results as $result) {
if ($result == '.' || $result == '..') {
Please register or sign in to reply
continue;
}
is_dir($path . $result) ? $extensions[] = $result : NULL;
}
$this->view->assign('extensions', $extensions);
}
/**
......@@ -48,10 +62,18 @@ class MailController extends ActionController {
public function showTemplatesAction() {
$extensionKey = $this->request->getArgument('ext_key');
$extPath = ExtensionManagementUtility::extPath(
Please register or sign in to reply
'sg_mail'
) . 'Configuration/Templates/' . $extensionKey . '/';
$files = glob($extPath . '*.html');
$this->view->assign('templates', array_map('basename', $files));
}
$files = glob('/path/to/dir/*.xml');
$this->view->assign('templates', MailTemplateService::$registerArray[$extensionKey]);
/**
*
*
*/
public function showMarkerAction() {
}
......
......@@ -42,18 +42,9 @@ class MailTemplateService {
* @param $template
* @return string
*/
public static function registerTemplate($extensionKey, $template) {
$path = ExtensionManagementUtility::extPath('sg_mail');
if (!file_exists($path . '/Configuration/Templates/' . $template . '.html')) {
// @TODO Throw exception
return;
}
public static function registerTemplate($extensionKey) {
if (!array_key_exists($extensionKey, MailTemplateService::$registerArray)) {
MailTemplateService::$registerArray[$extensionKey] = [$template];
} elseif (!in_array(MailTemplateService::$registerArray[$extensionKey], $template)) {
MailTemplateService::$registerArray[$extensionKey][] = $template;
MailTemplateService::$registerArray[$extensionKey];
}
}
}
......@@ -4,13 +4,12 @@
</f:section>
<f:section name="main">
<f:flashMessages renderMode="div" />
<f:debug>{extensions}</f:debug>
<h3>Registered Extensions</h3>
<ul class="list-group">
<f:for each="{extensions}" as="extension" key="key">
<f:for each="{extensions}" as="extension">
<li class="list-group-item">
<f:link.action controller="Mail" action="showTemplates" arguments="{ext_key:'{key}'}">{key}</f:link.action>
<span class="badge"><f:count>{extension}</f:count></span>
<f:link.action controller="Mail" action="showTemplates" arguments="{ext_key:'{extension}'}">{extension}</f:link.action>
</li>
</f:for>
</ul>
......
......@@ -4,8 +4,13 @@
</f:section>
<f:section name="main">
<f:flashMessages renderMode="div" />
<f:for each="{templates}" as="template">
{template}<br />
</f:for>
<ul class="list-group">
<f:for each="{templates}" as="template">
<li class="list-group-item">
<f:link.action controller="Mail" action="showMarker" arguments="{template:'{template}'}">
{template}
</f:link.action>
</li>
</f:for>
</ul>
</f:section>
......@@ -10,7 +10,7 @@ if (!defined('TYPO3_MODE')) {
'Mail',
'',
[
'Mail' => 'index, showTemplates',
'Mail' => 'index, showTemplates, showMarker',
],
[
'access' => 'admin,user,group',
......
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