Skip to content
Snippets Groups Projects
Commit 5454a720 authored by Stefan Galinski's avatar Stefan Galinski :video_game:
Browse files

[BUGFIX] Fix missing object exception on the live (strange, that this wasn't visible on the dev)

parent c63d2512
No related branches found
No related tags found
No related merge requests found
......@@ -27,8 +27,10 @@ namespace SGalinski\SgMail\Service;
***************************************************************/
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager;
use TYPO3\CMS\Extbase\Service\TypoScriptService;
use TYPO3\CMS\Extbase\Object\ObjectManager;
/**
* Returns the typoscript setup based on the page id
......@@ -36,7 +38,6 @@ use TYPO3\CMS\Extbase\Service\TypoScriptService;
*/
class TypoScriptSettingsService implements SingletonInterface {
/**
* @inject
* @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
*/
protected $objectManager;
......@@ -46,6 +47,13 @@ class TypoScriptSettingsService implements SingletonInterface {
*/
protected static $typoScriptCache = [];
/**
* Initializes the class
*/
public function __construct() {
$this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
}
/**
* Returns the typoscript settings of a given page and extension
*
......@@ -53,26 +61,21 @@ class TypoScriptSettingsService implements SingletonInterface {
* @param string $extensionKey
* @return array
*/
public function getSettings($pageId, $extensionKey) {
public function getSettings($pageId, $extensionKey): array {
$pageId = (int) $pageId;
if (!isset(self::$typoScriptCache[$extensionKey . $pageId])) {
$cacheHash = $extensionKey . $pageId;
if (!isset(self::$typoScriptCache[$cacheHash])) {
$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(
$typoScriptService = $this->objectManager->get(TypoScriptService::class);
$configurationManager = $this->objectManager->get(BackendConfigurationManager::class);
self::$typoScriptCache[$cacheHash] = $typoScriptService->convertTypoScriptArrayToPlainArray(
(array) $configurationManager->getTypoScriptSetup()['module.'][$extensionKey . '.']['settings.']
);
$_POST['id'] = $tmpId;
}
return self::$typoScriptCache[$extensionKey . $pageId];
return self::$typoScriptCache[$cacheHash];
}
}
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