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

[TASK] Adding Service class to read ts Settings in other classes

parent 5696628a
......@@ -66,7 +66,7 @@ class MailTemplateService {
/**
* @var string language
*/
private $language = 'de';
private $language;
/**
* @var boolean ignoreMailQueue
......@@ -98,12 +98,23 @@ class MailTemplateService {
*/
private $subject;
/**
* holds the TypoScript configuration for sg_mail
*
* @var array tsSettings
*/
private $tsSettings = [];
/**
* MailTemplateService constructor.
*/
public function __construct() {
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$this->mailMessage = $objectManager->get(MailMessage::class);
$typoScriptSettingsService = $objectManager->get(TypoScriptSettingsService::class);
$this->tsSettings = $typoScriptSettingsService->getSettings(0, 'tx_sgmail');
$this->language = $this->tsSettings['templateDefaultLanguage'];
}
/**
......@@ -140,8 +151,7 @@ class MailTemplateService {
* Send the Email
*/
public function sendEmail() {
$registerArray = MailTemplateService::getRegisterArray();
$templateEntry = $registerArray[$this->extensionKey][$this->templateName];
$templateEntry = self::$registerArray[$this->extensionKey][$this->templateName];
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$emailView = $objectManager->get(StandaloneView::class);
......
<?php
namespace SGalinski\SgMail\Service;
/***************************************************************
* 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\Core\SingletonInterface;
use TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager;
use TYPO3\CMS\Extbase\Service\TypoScriptService;
/**
* Returns the typoscript setup based on the page id
*
*/
class TypoScriptSettingsService implements SingletonInterface {
/**
* @inject
* @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
*/
protected $objectManager;
/**
* @var array
*/
protected static $typoScriptCache = [];
/**
* Returns the typoscript settings of a given page and extension
*
* @param int $pageId
* @param string $extensionKey
* @return array
*/
public function getSettings($pageId, $extensionKey) {
$pageId = (int) $pageId;
if (!isset(self::$typoScriptCache[$extensionKey . $pageId])) {
$tmpId = $_POST['id'];
$_POST['id'] = $pageId;
/** @var TypoScriptService $typoScriptService */
$class = 'TYPO3\CMS\Extbase\Service\TypoScriptService';
$typoScriptService = $this->objectManager->get($class);
/** @var BackendConfigurationManager $configurationManager */
$class = 'TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager';
$configurationManager = $this->objectManager->get($class);
self::$typoScriptCache[$extensionKey . $pageId] = $typoScriptService->convertTypoScriptArrayToPlainArray(
(array) $configurationManager->getTypoScriptSetup()['module.'][$extensionKey . '.']['settings.']
);
$_POST['id'] = $tmpId;
}
return self::$typoScriptCache[$extensionKey . $pageId];
}
}
......@@ -10,6 +10,7 @@ module.tx_sgmail {
from.test = info@test.de
}
templateDefaultLanguage = de
template.filename = mail_template.html
}
}
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