‪TYPO3CMS  10.4
BackendConfigurationManager.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
30 
36 {
40  protected ‪$typoScriptSetupCache = [];
41 
46  protected ‪$currentPageId;
47 
53  public function ‪getTypoScriptSetup(): array
54  {
55  $pageId = $this->‪getCurrentPageId();
56 
57  if (!array_key_exists($pageId, $this->typoScriptSetupCache)) {
59  $template = GeneralUtility::makeInstance(TemplateService::class);
60  // do not log time-performance information
61  $template->tt_track = false;
62  // Explicitly trigger processing of extension static files
63  $template->setProcessExtensionStatics(true);
64  // Get the root line
65  $rootline = [];
66  if ($pageId > 0) {
67  try {
68  $rootline = GeneralUtility::makeInstance(RootlineUtility::class, $pageId)->get();
69  } catch (\RuntimeException $e) {
70  $rootline = [];
71  }
72  }
73  // This generates the constants/config + hierarchy info for the template.
74  $template->runThroughTemplates($rootline, 0);
75  $template->generateConfig();
76  $this->typoScriptSetupCache[$pageId] = $template->setup;
77  }
78  return $this->typoScriptSetupCache[$pageId];
79  }
80 
89  protected function ‪getPluginConfiguration(string ‪$extensionName, string ‪$pluginName = null): array
90  {
91  $setup = $this->‪getTypoScriptSetup();
92  $pluginConfiguration = [];
93  if (is_array($setup['module.']['tx_' . strtolower(‪$extensionName) . '.'] ?? false)) {
94  $pluginConfiguration = $this->typoScriptService->convertTypoScriptArrayToPlainArray($setup['module.']['tx_' . strtolower(‪$extensionName) . '.']);
95  }
96  if (‪$pluginName !== null) {
97  $pluginSignature = strtolower(‪$extensionName . '_' . ‪$pluginName);
98  if (is_array($setup['module.']['tx_' . $pluginSignature . '.'] ?? false)) {
99  $overruleConfiguration = $this->typoScriptService->convertTypoScriptArrayToPlainArray($setup['module.']['tx_' . $pluginSignature . '.']);
100  ‪ArrayUtility::mergeRecursiveWithOverrule($pluginConfiguration, $overruleConfiguration);
101  }
102  }
103  return $pluginConfiguration;
104  }
105 
117  protected function ‪getControllerConfiguration(string ‪$extensionName, string ‪$pluginName): array
118  {
119  $controllerConfiguration = ‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][‪$extensionName]['modules'][‪$pluginName]['controllers'] ?? false;
120  if (!is_array($controllerConfiguration)) {
121  $controllerConfiguration = [];
122  }
123  return $controllerConfiguration;
124  }
125 
132  protected function ‪getCurrentPageId(): int
133  {
134  if ($this->currentPageId !== null) {
136  }
137 
138  $this->currentPageId = $this->‪getCurrentPageIdFromGetPostData() ?: $this->‪getCurrentPageIdFromCurrentSiteRoot();
139  $this->currentPageId = $this->currentPageId ?: $this->‪getCurrentPageIdFromRootTemplate();
140  $this->currentPageId = $this->currentPageId ?: ‪self::DEFAULT_BACKEND_STORAGE_PID;
141 
143  }
144 
150  protected function ‪getCurrentPageIdFromGetPostData(): int
151  {
152  return (int)GeneralUtility::_GP('id');
153  }
154 
160  protected function ‪getCurrentPageIdFromCurrentSiteRoot(): int
161  {
162  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
163  ->getQueryBuilderForTable('pages');
164 
165  $queryBuilder
166  ->getRestrictions()
167  ->removeAll()
168  ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
169  ->add(GeneralUtility::makeInstance(HiddenRestriction::class));
170 
171  $rootPage = $queryBuilder
172  ->select('uid')
173  ->from('pages')
174  ->where(
175  $queryBuilder->expr()->eq('is_siteroot', $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT)),
176  $queryBuilder->expr()->eq('sys_language_uid', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)),
177  // Only consider live root page IDs, never return a versioned root page ID
178  $queryBuilder->expr()->eq('t3ver_oid', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)),
179  $queryBuilder->expr()->eq('t3ver_wsid', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT))
180  )
181  ->orderBy('sorting')
182  ->execute()
183  ->fetch();
184 
185  if (empty($rootPage)) {
186  return 0;
187  }
188 
189  return (int)$rootPage['uid'];
190  }
191 
197  protected function ‪getCurrentPageIdFromRootTemplate(): int
198  {
199  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
200  ->getQueryBuilderForTable('sys_template');
201 
202  $queryBuilder
203  ->getRestrictions()
204  ->removeAll()
205  ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
206  ->add(GeneralUtility::makeInstance(HiddenRestriction::class));
207 
208  $rootTemplate = $queryBuilder
209  ->select('pid')
210  ->from('sys_template')
211  ->where(
212  $queryBuilder->expr()->eq('root', $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT))
213  )
214  ->orderBy('crdate')
215  ->execute()
216  ->fetch();
217 
218  if (empty($rootTemplate)) {
219  return 0;
220  }
221 
222  return (int)$rootTemplate['pid'];
223  }
224 
230  public function ‪getDefaultBackendStoragePid(): int
231  {
232  // todo: fallback to parent::getDefaultBackendStoragePid() would make sense here.
233  return $this->‪getCurrentPageId();
234  }
235 
244  protected function ‪getContextSpecificFrameworkConfiguration(array $frameworkConfiguration): array
245  {
246  return $frameworkConfiguration;
247  }
248 
256  protected function ‪getRecursiveStoragePids(array $storagePids, $recursionDepth = 0): array
257  {
258  array_map('intval', $storagePids);
259 
260  if ($recursionDepth <= 0) {
261  return $storagePids;
262  }
263 
264  $recursiveStoragePids = [];
266  $queryGenerator = GeneralUtility::makeInstance(QueryGenerator::class);
267  foreach ($storagePids as $startPid) {
268  $pids = $queryGenerator->getTreeList($startPid, $recursionDepth, 0, $permsClause);
269  foreach (‪GeneralUtility::intExplode(',', $pids, true) as $pid) {
270  $recursiveStoragePids[] = $pid;
271  }
272  }
273 
274  return array_unique($recursiveStoragePids);
275  }
276 
280  protected function ‪getBackendUser(): ‪BackendUserAuthentication
281  {
282  return ‪$GLOBALS['BE_USER'];
283  }
284 }
‪TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction
Definition: HiddenRestriction.php:27
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\$pluginName
‪string $pluginName
Definition: AbstractConfigurationManager.php:68
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager\getBackendUser
‪TYPO3 CMS Core Authentication BackendUserAuthentication getBackendUser()
Definition: BackendConfigurationManager.php:278
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\getPagePermsClause
‪string getPagePermsClause($perms)
Definition: BackendUserAuthentication.php:499
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager
Definition: BackendConfigurationManager.php:36
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager\getCurrentPageId
‪int getCurrentPageId()
Definition: BackendConfigurationManager.php:130
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager\getRecursiveStoragePids
‪array int[] getRecursiveStoragePids(array $storagePids, $recursionDepth=0)
Definition: BackendConfigurationManager.php:254
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager\getPluginConfiguration
‪array getPluginConfiguration(string $extensionName, string $pluginName=null)
Definition: BackendConfigurationManager.php:87
‪TYPO3\CMS\Core\Utility\RootlineUtility
Definition: RootlineUtility.php:39
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager\getCurrentPageIdFromGetPostData
‪int getCurrentPageIdFromGetPostData()
Definition: BackendConfigurationManager.php:148
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager\getCurrentPageIdFromRootTemplate
‪int getCurrentPageIdFromRootTemplate()
Definition: BackendConfigurationManager.php:195
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager\$currentPageId
‪int $currentPageId
Definition: BackendConfigurationManager.php:44
‪TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule
‪static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
Definition: ArrayUtility.php:654
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager
Definition: AbstractConfigurationManager.php:34
‪TYPO3\CMS\Core\Database\QueryGenerator
Definition: QueryGenerator.php:32
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:24
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager\getControllerConfiguration
‪array getControllerConfiguration(string $extensionName, string $pluginName)
Definition: BackendConfigurationManager.php:115
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager\getTypoScriptSetup
‪array getTypoScriptSetup()
Definition: BackendConfigurationManager.php:51
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager\getCurrentPageIdFromCurrentSiteRoot
‪int getCurrentPageIdFromCurrentSiteRoot()
Definition: BackendConfigurationManager.php:158
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager\getContextSpecificFrameworkConfiguration
‪array getContextSpecificFrameworkConfiguration(array $frameworkConfiguration)
Definition: BackendConfigurationManager.php:242
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_SHOW
‪const PAGE_SHOW
Definition: Permission.php:33
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager\$typoScriptSetupCache
‪array $typoScriptSetupCache
Definition: BackendConfigurationManager.php:39
‪TYPO3\CMS\Core\TypoScript\TemplateService
Definition: TemplateService.php:46
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:24
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
Definition: DeletedRestriction.php:28
‪TYPO3\CMS\Core\Utility\GeneralUtility\intExplode
‪static int[] intExplode($delimiter, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:988
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Extbase\Configuration
Definition: AbstractConfigurationManager.php:18
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager\getDefaultBackendStoragePid
‪int getDefaultBackendStoragePid()
Definition: BackendConfigurationManager.php:228
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\$extensionName
‪string $extensionName
Definition: AbstractConfigurationManager.php:62
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\DEFAULT_BACKEND_STORAGE_PID
‪const DEFAULT_BACKEND_STORAGE_PID
Definition: AbstractConfigurationManager.php:38