Commit cda7800e authored by Torsten Oppermann's avatar Torsten Oppermann
Browse files

[TASK] Changed UI, old registry with new options like language templates

parent 4cf8a87e
......@@ -26,7 +26,7 @@ namespace SGalinski\SgMail\Controller;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use SGalinski\SgMail\Service\MailTemplateService;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
/**
......@@ -38,36 +38,26 @@ class MailController extends ActionController {
*
*/
public function indexAction() {
$path = ExtensionManagementUtility::extPath(
'sg_mail'
) . 'Configuration/Templates/';
$results = scandir($path);
$this->view->assign('templates', MailTemplateService::getRegisterArray());
$extensions = [];
foreach ($results as $result) {
if ($result == '.' || $result == '..') {
continue;
}
is_dir($path . $result) ? $extensions[] = $result : NULL;
if ($this->request->hasArgument('key')) {
$extensionKey = $this->request->getArgument('key');
} else {
reset(MailTemplateService::getRegisterArray());
$extensionKey = key(MailTemplateService::getRegisterArray());
}
$this->view->assign('extensions', $extensions);
if (key_exists($extensionKey, MailTemplateService::getRegisterArray())) {
$this->view->assign('selection', MailTemplateService::getRegisterArray()[$extensionKey]);
}
}
/**
*
*
*/
public function showTemplatesAction() {
$extensionKey = $this->request->getArgument('ext_key');
public function showTemplateAction() {
$extPath = ExtensionManagementUtility::extPath(
'sg_mail'
) . 'Configuration/Templates/' . $extensionKey . '/';
$files = glob($extPath . '*.html');
$this->view->assign('templates', array_map('basename', $files));
$this->view->assign('extensionKey', $extensionKey);
}
/**
......@@ -75,19 +65,13 @@ class MailController extends ActionController {
*
*/
public function showMarkerAction() {
$extensionKey = $this->request->getArgument('extensionKey');
$template = $this->request->getArgument('template');
$templateContent = file_get_contents(
ExtensionManagementUtility::extPath(
'sg_mail'
) . 'Configuration/Templates/' . $extensionKey . '/' . $template
);
$marker = preg_match_all('/(?<={)[^}]+(?=})/', $templateContent, $matches) ? $matches[0] : [];
$comments = preg_match_all('/<!--(.|\s)*?-->/', $templateContent, $matches) ? $matches[0] : [];
}
$this->view->assign('marker', $marker);
$this->view->assign('comments', $comments);
/**
*
* @param array $marker
*/
public function saveMarkerAction(array $marker = []) {
}
}
......@@ -2,30 +2,30 @@
namespace SGalinski\SgMail\Service;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (https://www.sgalinski.de)
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (https://www.sgalinski.de)
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Core\SingletonInterface;
/**
* MailTemplateService
......@@ -33,24 +33,30 @@ use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
class MailTemplateService {
/**
* Holds default values for all Templates and their markers
* @var array
*/
protected $templateConfig = [];
private static $registerArray = [];
/**
* @var array
* @param string $extensionKey
* @param string $template
* @param array $marker
* @return string
*/
public static $registerArray = [];
public static function registerTemplate($extension, $templateName, $templateFiles, $description, array $marker) {
MailTemplateService::$registerArray[$templateName] = [
'description' => $description,
'templateFiles' => $templateFiles,
'marker' => $marker,
'extension' => $extension
];
}
/**
* @param $extensionKey
* @param $template
* @return string
* @return array
*/
public static function registerTemplate($extensionKey) {
if (!array_key_exists($extensionKey, MailTemplateService::$registerArray)) {
MailTemplateService::$registerArray[$extensionKey];
}
public static function getRegisterArray() {
return self::$registerArray;
}
}
<?php
namespace SGalinski\SgMail\Domain\Repository;
namespace SGalinski\SgMail\ViewHelpers;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (https://www.sgalinski.de)
* (c) sgalinski Internet Services (http://www.sgalinski.de)
*
* All rights reserved
*
......@@ -26,39 +26,48 @@ namespace SGalinski\SgMail\Domain\Repository;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Core\Database\DatabaseConnection;
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;
use TYPO3\CMS\Extbase\Persistence\Repository;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper;
/**
* The repository for RegisteredExtensions
* Abstract view helper
*/
class RegisteredTemplateRepository extends Repository {
class AbstractViewHelper extends AbstractBackendViewHelper {
/**
* Initializes the repository default settings
* Returns an instance of the page renderer
*
* @return void
* @deprecated Implement the following migration if the extension just needs to support > 7.5.
* @return PageRenderer
*/
public function initializeObject() {
/** @TODO removing this doesnt work. talk about it in meeting */
/** @var $querySettings Typo3QuerySettings */
$querySettings = $this->objectManager->get(Typo3QuerySettings::class);
$querySettings->setRespectStoragePage(FALSE);
public function getPageRenderer() {
// Migration
// return $this->objectManager->get(\TYPO3\CMS\Core\Page\PageRenderer::class);
if (TYPO3_MODE === 'BE') {
$pageRenderer = $this->getDocInstance()->getPageRenderer();
} else {
/** @noinspection PhpUndefinedMethodInspection */
$pageRenderer = $GLOBALS['TSFE']->getPageRenderer();
}
$this->setDefaultQuerySettings($querySettings);
return $pageRenderer;
}
/**
* @param $registeredTemplate
* Returns the base url of the site
*
* Note: Works only in frontend mode
*
* @return string
*/
public static function addTemplate($extensionKey, $template) {
/** @var $databaseConnection DatabaseConnection */
$databaseConnection = $GLOBALS['TYPO3_DB'];
public function getBaseUrl() {
if ($GLOBALS['TSFE']->absRefPrefix !== '') {
$baseUrl = $GLOBALS['TSFE']->absRefPrefix;
} else {
$baseUrl = $GLOBALS['TSFE']->baseUrl;
}
$fieldsValues = [
'ext_key' => $extensionKey, 'template' => $template, 'mail_key' => uniqid()
];
$databaseConnection->exec_INSERTquery($table, $fieldsValues);
return $baseUrl;
}
}
?>
<?php
namespace SGalinski\SgMail\Domain\Model;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
namespace SGalinski\SgMail\ViewHelpers\Be\Menus;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (https://www.sgalinski.de)
* (c) sgalinski Internet Services (http://www.sgalinski.de)
*
* All rights reserved
*
......@@ -28,72 +26,34 @@ use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
/**
* The RegisteredTemplate Model
* Class ActionMenuOptionGroupViewHelper
*/
class RegisteredTemplate extends AbstractEntity {
/**
* extKey
*
* @var string
*/
protected $extKey;
class ActionMenuOptionGroupViewHelper extends AbstractTagBasedViewHelper {
/**
* template
*
* @var string
*/
protected $template;
protected $tagName = 'optgroup';
/**
* mailKey
* Initialize
*
* @var string
*/
protected $mailKey;
/**
* @return string
*/
public function getExtKey() {
return $this->extKey;
}
/**
* @param string $extKey
*/
public function setExtKey($extKey) {
$this->extKey = $extKey;
}
/**
* @return string
*/
public function getTemplate() {
return $this->template;
}
/**
* @param string $template
* @return void
*/
public function setTemplate($template) {
$this->template = $template;
public function initializeArguments() {
parent::initializeArguments();
$this->registerUniversalTagAttributes();
$this->registerTagAttribute('label', 'string', 'Specifies a label for an option-group');
$this->registerTagAttribute('disabled', 'string', 'Specifies that an option-group should be disabled');
}
/**
* @return string
*/
public function getMailKey() {
return $this->mailKey;
}
/**
* @param string $mailKey
*/
public function setMailKey($mailKey) {
$this->mailKey = $mailKey;
public function render() {
$this->tag->setContent($this->renderChildren());
return $this->tag->render();
}
}
<?php
namespace SGalinski\SgMail\ViewHelpers;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (http://www.sgalinski.de)
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
/**
* ExtendedIfViewHelper
*/
class ExtendedIfViewHelper extends AbstractConditionViewHelper {
/**
* Initializes the "then" and "else" arguments
*/
public function initializeArguments() {
parent::initializeArguments();
$this->registerArgument('condition', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, FALSE);
$this->registerArgument('or', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, FALSE);
$this->registerArgument('or2', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, FALSE);
$this->registerArgument('or3', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, FALSE);
$this->registerArgument('or4', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, FALSE);
$this->registerArgument('and', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, TRUE);
$this->registerArgument('and2', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, TRUE);
$this->registerArgument('and3', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, TRUE);
$this->registerArgument('and4', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, TRUE);
$this->registerArgument('negate', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, FALSE);
}
/**
* renders <f:then> child if $condition or $or is true, otherwise renders <f:else> child.
*
* @return string
*/
public function render() {
if ($this->evaluateConditionFunctionExists()) {
return parent::render();
}
// @todo Remove the following part if only > 7.5 support.
$conditionResult = ($this->arguments['condition'] || $this->arguments['or'] || $this->arguments['or2'] || $this->arguments['or3'] || $this->arguments['or4'])
&& $this->arguments['and'] && $this->arguments['and2'] && $this->arguments['and3'] && $this->arguments['and4'];
if ($this->arguments['negate'] ? !$conditionResult : $conditionResult) {
return $this->renderThenChild();
} else {
return $this->renderElseChild();
}
}
/**
* This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality.
*
* @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
* @return bool
*/
static protected function evaluateCondition($arguments = NULL) {
$conditionResult = (
isset($arguments['condition']) && $arguments['condition'] ||
isset($arguments['or']) && $arguments['or'] ||
isset($arguments['or2']) && $arguments['or2'] ||
isset($arguments['or3']) && $arguments['or3'] ||
isset($arguments['or4']) && $arguments['or4']
) && isset($arguments['and']) && $arguments['and'] &&
isset($arguments['and2']) && $arguments['and2'] &&
isset($arguments['and3']) && $arguments['and3'] &&
isset($arguments['and4']) && $arguments['and4'];
return isset($arguments['negate']) && $arguments['negate'] ? !$conditionResult : $conditionResult;
}
/**
* Returns true, if the function evaluateCondition exists in the AbstractConditionViewHelper class.
*
* @deprecated Remove this function if only > 7.5 support.
* @return boolean
*/
protected function evaluateConditionFunctionExists() {
return method_exists('TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper', 'evaluateCondition');
}
}
?>
<?php
namespace SGalinski\SgMail\ViewHelpers;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (http://www.sgalinski.de)
*
* All rights reserved
*
* This script is part of the AY project. The AY project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
/**
* View helper to render language labels to
* json array to be used in js applications.
*
* Renders to AY.lang.'extension name' object
*
* Example:
* {namespace rs=SGalinski\RsEvents\ViewHelpers}
* <rs:inlineLanguageLabels labels="label01,label02" />
*/
class InlineLanguageLabelsViewHelper extends AbstractViewHelper {
/**
* Renders the required javascript to make the language labels available
*
* @param string $labels Comma separated list of label keys to include
* @param boolean $htmlEscape
* @return string
*/
public function render($labels = '', $htmlEscape = FALSE) {
$extensionName = $this->controllerContext->getRequest()->getControllerExtensionName();
$labels = GeneralUtility::trimExplode(',', $labels, TRUE);
$languageArray = array();
foreach ($labels as $key) {
$value = LocalizationUtility::translate($key, $extensionName);
$languageArray[$key] = ($htmlEscape ? htmlentities($value) : $value);
}
return '
<script type="text/javascript">
var AY = AY || {};
AY.lang = AY.lang || {};
AY.lang.' . $extensionName . ' = AY.lang.' . $extensionName . ' || {};
var languageLabels = ' . json_encode($languageArray) . ';
for (label in languageLabels) {
AY.lang.' . $extensionName . '[label] = languageLabels[label];
}
</script>
';
}
}
?>
<?php
if (!defined('TYPO3_MODE')) {
die ('Access denied.');
}
return [
'ctrl' => [
'title' => 'LLL:EXT:sg_mail/Resources/Private/Language/locallang_db.xlf:tx_sg_mail_domain_model_registeredtemplate',
'label' => '',
'tstamp' => 'tstamp',
'crdate' => 'crdate',
'cruser_id' => 'cruser_id',
'dividers2tabs' => TRUE,
'versioningWS' => 2,
'versioning_followPages' => TRUE,
'languageField' => 'sys_language_uid',
'transOrigPointerField' => 'l10n_parent',
'transOrigDiffSourceField' => 'l10n_diffsource',
'delete' => 'deleted',
'enablecolumns' => [
'disabled' => 'hidden'
],
'searchFields' => 'ext_key, template, mail_key',
'iconfile' => 'EXT:sg_mail/Resources/Public/Icons/ModuleIcon.svg'
],
'interface' => [
'showRecordFieldList' => 'sys_language_uid, l10n_parent, l10n_diffsource, hidden, ext_key, template, mail_key',
],
'types' => [
'1' => ['showitem' => 'ext_key, template, mail_key, --div--;LLL:EXT:cms/locallang_ttc.xlf:tabs.access, hidden;;1;;, sys_language_uid;;6;;,'],
],
'palettes' => [
'1' => ['showitem' => 'ext_key, template, mail_key'],
'2' => ['showitem' => 'l10n_parent, l10n_diffsource,'],
],
'columns' => [
'sys_language_uid' => [
'exclude' => 1,
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.language',
'config' => [
'type' => 'select',
'foreign_table' => 'sys_language',
'foreign_table_where' => 'ORDER BY sys_language.title',
'items' => [
['LLL:EXT:lang/locallang_general.xlf:LGL.allLanguages', -1],
['LLL:EXT:lang/locallang_general.xlf:LGL.default_value', 0]
],
],
],
'l10n_parent' => [
'displayCond' => 'FIELD:sys_language_uid:>:0',
'exclude' => 1,
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.l18n_parent',
'config' => [
'type' => 'select',
'items' => [
['', 0],