-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypoScriptService.php
More file actions
71 lines (60 loc) · 2.39 KB
/
Copy pathTypoScriptService.php
File metadata and controls
71 lines (60 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
namespace Fab\Formule\Service;
/*
* This file is part of the Fab/Formule project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Http\ApplicationType;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager;
/**
* TypoScriptService
*/
class TypoScriptService implements SingletonInterface
{
/**
* Public DI alias id, see Configuration/Services.yaml
*/
private const BACKEND_CONFIGURATION_MANAGER_SERVICE_ID = 'fab.formule.backend_configuration_manager';
/**
* @var array
*/
protected $settings = [];
/**
* Returns the TypoScript configuration for this extension.
*
* @return array
*/
public function getSettings(): array
{
// Use cache or initialize settings property.
if (empty($this->settings)) {
if ($this->isFrontendMode()) {
$this->settings = GeneralUtility::removeDotsFromTS($GLOBALS['TYPO3_REQUEST']->getAttribute('frontend.typoscript')->getSetupArray()['plugin.']['tx_formule.']['settings.']);
} else {
$request = $GLOBALS['TYPO3_REQUEST'] ?? null;
if ($request instanceof ServerRequestInterface) {
$setup = $this->resolveBackendConfigurationManager()->getTypoScriptSetup($request);
if (is_array($setup['plugin.']['tx_formule.'])) {
/** @var \TYPO3\CMS\Core\TypoScript\TypoScriptService $typoScriptService */
$typoScriptService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\TypoScriptService::class);
$this->settings = $typoScriptService->convertTypoScriptArrayToPlainArray($setup['plugin.']['tx_formule.']['settings.']);
}
}
}
}
return $this->settings;
}
protected function resolveBackendConfigurationManager(): BackendConfigurationManager
{
return GeneralUtility::getContainer()->get(self::BACKEND_CONFIGURATION_MANAGER_SERVICE_ID);
}
protected function isFrontendMode(): bool
{
return ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend();
}
}