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

[TASK] Updating Views, Viewhelpers and Controller

parent 52f971de
No related branches found
No related tags found
1 merge request!1Feature sg mail
......@@ -54,21 +54,31 @@ class MailController extends ActionController {
$this->view->assign('languages', $languages);
$this->view->assign('templates', MailTemplateService::getRegisterArray());
if ($this->request->hasArgument('selectedTemplate')) {
if ($this->request->hasArgument('selectedTemplate') && !$this->request->hasArgument('selectedLanguage')) {
$registerArray = MailTemplateService::getRegisterArray();
$selectedTemplate = $registerArray[$this->request->getArgument('selectedTemplate')];
$this->view->assign('selectedTemplate', $selectedTemplate);
$this->view->assign('selectedTemplateKey', $this->request->getArgument('selectedTemplate'));
} else {
} elseif (!$this->request->hasArgument('selectedLanguage')) {
reset(MailTemplateService::getRegisterArray());
$firstEntry = key(MailTemplateService::getRegisterArray());
$this->view->assign('selectedTemplate', MailTemplateService::getRegisterArray()[$firstEntry]);
$this->view->assign('selectedTemplateKey', $firstEntry);
}
if ($this->request->hasArgument('selectedLanguage')) {
$this->view->assign('selectedLanguage', $this->request->hasArgument('selectedLanguage'));
if ($this->request->hasArgument('selectedLanguage')
&& $this->request->hasArgument('selectedTemplate')
&& $this->request->hasArgument('selectedTemplateKey')
) {
$this->view->assign('selectedLanguage', $this->request->getArgument('selectedLanguage'));
$this->view->assign('selectedTemplate', $this->request->getArgument('selectedTemplate'));
$this->view->assign('selectedTemplateKey', $this->request->getArgument('selectedTemplateKey'));
} else {
$this->view->assign('selectedLanguage', 'en');
}
......
......@@ -26,27 +26,38 @@ namespace SGalinski\SgMail\Service;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Lang\Domain\Model\Language;
use TYPO3\CMS\Lang\Domain\Repository\LanguageRepository;
/**
* MailTemplateService
*/
class MailTemplateService {
/**
* @var \TYPO3\CMS\Lang\Domain\Repository\LanguageRepository
* @inject
*/
protected static $languageRepository = NULL;
/**
* @var array
*/
private static $registerArray = [];
/**
* @param string $extension
* @param string $extensionKey
* @param string $template
* @param array $marker
* @return string
*/
public static function registerTemplate($extension, $templateName, $templateFiles, $description, array $marker) {
public static function registerTemplate($extension, $templateName, $templatePath, $description, array $marker) {
MailTemplateService::$registerArray[$templateName] = [
'templatePath' => $templatePath,
'description' => $description,
'templateFiles' => $templateFiles,
'marker' => $marker,
'extension' => $extension
];
......@@ -58,5 +69,4 @@ class MailTemplateService {
public static function getRegisterArray() {
return self::$registerArray;
}
}
<?php
namespace SGalinski\SgMail\ViewHelpers\Be\Menus;
/***************************************************************
* 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!
***************************************************************/
/**
* Class ActionMenuItemViewHelper
*
* This is just a re-implemntation of the core view helper with the same name
* only difference so far is the selected option is not automatically set if you cann the same action&controller
*
* @package SGalinski\SgMail\ViewHelpers\Be\Menus
*/
class ActionMenuItemViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper {
/**
* @var string
*/
protected $tagName = 'option';
/**
* Renders an ActionMenu option tag
*
* @param string $label label of the option tag
* @param string $controller controller to be associated with this ActionMenuItem
* @param string $action the action to be associated with this ActionMenuItem
* @param array $arguments additional controller arguments to be passed to the action when this ActionMenuItem is selected
* @return string the rendered option tag
* @see \TYPO3\CMS\Fluid\ViewHelpers\Be\Menus\ActionMenuViewHelper
*/
public function render($label, $controller, $action, array $arguments = []) {
$uriBuilder = $this->controllerContext->getUriBuilder();
$uri = $uriBuilder->reset()->uriFor($action, $arguments, $controller);
$this->tag->addAttribute('value', $uri);
$currentRequest = $this->controllerContext->getRequest();
$currentController = $currentRequest->getControllerName();
$currentAction = $currentRequest->getControllerActionName();
$this->tag->setContent($label);
return $this->tag->render();
}
}
......@@ -9,24 +9,21 @@
<f:be.menus.actionMenu>
<f:for each="{templates}" as="template" key="templateKey">
<sgm:be.menus.actionMenuOptionGroup label="{template.extension}">
<f:for each="{template.templateFiles}" as="langFileLabel" key="langFileOption">
<sgm:extendedIf condition="{template.extension} == {extensionSelection}"
and="{langFileOption} == {languageFileSelection}">
<sgm:extendedIf condition="{selectedTemplateKey} == {templateKey}">
<f:then>
<f:be.menus.actionMenuItem label="{langFileLabel}"
controller="{controllerName}"
action="changeSelection"
arguments="{extensionSelection: extAddress, languageFileSelection: langFileOption}"
<sgm:be.menus.actionMenuItem label="{templateKey}"
controller="Mail"
action="index"
arguments="{selectedTemplate: templateKey}"
additionalAttributes="{selected: 'selected'}" />
</f:then>
<f:else>
<f:be.menus.actionMenuItem label="{langFileLabel}"
controller="{controllerName}"
action="changeSelection"
arguments="{extensionSelection: extAddress, languageFileSelection: langFileOption}" />
<sgm:be.menus.actionMenuItem label="{templateKey}"
controller="Mail"
action="index"
arguments="{selectedTemplate: templateKey}"/>
</f:else>
</sgm:extendedIf>
</f:for>
</sgm:be.menus.actionMenuOptionGroup>
</f:for>
</f:be.menus.actionMenu>
......
{namespace sgm=SGalinski\SgMail\ViewHelpers}
<f:layout name="Default" />
<f:section name="iconButtons">
&nbsp;
</f:section>
<f:section name="main">
<f:flashMessages renderMode="div" />
<strong>{selectedTemplate.templatePath}</strong>
<table class="table table-hover">
<thead>
<tr>
<th>Marker</th>
<th>Value</th>
<th>Description</th>
</tr>
</thead>
<f:for each="{selectedTemplate.marker}" as="marker">
<tr>
<td>{marker.marker}</td>
<td>{marker.value}</td>
<td>{marker.description}</td>
</tr>
</f:for>
</table>
<f:be.menus.actionMenu>
<f:for each="{languages}" as="language">
<sgm:extendedIf condition="{language} == {selectedLanguage}">
<f:then>
<sgm:be.menus.actionMenuItem label="{language}"
controller="Mail"
action="index"
arguments="{selectedLanguage: language, selectedTemplate: selectedTemplate, selectedTemplateKey: selectedTemplateKey}"
additionalAttributes="{selected: 'selected'}" />
</f:then>
<f:else>
<sgm:be.menus.actionMenuItem label="{language}"
controller="Mail"
action="index"
arguments="{selectedLanguage: language, selectedTemplate: selectedTemplate, selectedTemplateKey: selectedTemplateKey}" />
</f:else>
</sgm:extendedIf>
</f:for>
</f:be.menus.actionMenu>
<f:form method="post" controller="Mail" action="save">
<br />
<f:form.textarea class="col-md-5" rows="25"></f:form.textarea>
<br />
<f:form.submit class="btn-default col-md-1" value="Save" />
</f:form>
</f:section>
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