‪TYPO3CMS  9.5
BackendConfigurationManager.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
28 
34 {
38  protected ‪$typoScriptSetupCache = [];
39 
44  protected ‪$currentPageId;
45 
51  public function ‪getTypoScriptSetup()
52  {
53  $pageId = $this->‪getCurrentPageId();
54 
55  if (!array_key_exists($pageId, $this->typoScriptSetupCache)) {
57  $template = GeneralUtility::makeInstance(TemplateService::class);
58  // do not log time-performance information
59  $template->tt_track = false;
60  // Explicitly trigger processing of extension static files
61  $template->setProcessExtensionStatics(true);
62  // Get the root line
63  $rootline = [];
64  if ($pageId > 0) {
65  try {
66  $rootline = GeneralUtility::makeInstance(RootlineUtility::class, $pageId)->get();
67  } catch (\RuntimeException $e) {
68  $rootline = [];
69  }
70  }
71  // This generates the constants/config + hierarchy info for the template.
72  $template->runThroughTemplates($rootline, 0);
73  $template->generateConfig();
74  $this->typoScriptSetupCache[$pageId] = $template->setup;
75  }
76  return $this->typoScriptSetupCache[$pageId];
77  }
78 
88  {
89  $setup = $this->‪getTypoScriptSetup();
90  $pluginConfiguration = [];
91  if (is_array($setup['module.']['tx_' . strtolower(‪$extensionName) . '.'] ?? false)) {
92  $pluginConfiguration = $this->typoScriptService->convertTypoScriptArrayToPlainArray($setup['module.']['tx_' . strtolower(‪$extensionName) . '.']);
93  }
94  if (‪$pluginName !== null) {
95  $pluginSignature = strtolower(‪$extensionName . '_' . ‪$pluginName);
96  if (is_array($setup['module.']['tx_' . $pluginSignature . '.'] ?? false)) {
97  $overruleConfiguration = $this->typoScriptService->convertTypoScriptArrayToPlainArray($setup['module.']['tx_' . $pluginSignature . '.']);
98  ‪ArrayUtility::mergeRecursiveWithOverrule($pluginConfiguration, $overruleConfiguration);
99  }
100  }
101  return $pluginConfiguration;
102  }
103 
116  {
117  $switchableControllerActions = ‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][‪$extensionName]['modules'][‪$pluginName]['controllers'] ?? false;
118  if (!is_array($switchableControllerActions)) {
119  $switchableControllerActions = [];
120  }
121  return $switchableControllerActions;
122  }
123 
130  protected function ‪getCurrentPageId()
131  {
132  if ($this->currentPageId !== null) {
134  }
135 
136  $this->currentPageId = $this->‪getCurrentPageIdFromGetPostData() ?: $this->‪getCurrentPageIdFromCurrentSiteRoot();
137  $this->currentPageId = $this->currentPageId ?: $this->‪getCurrentPageIdFromRootTemplate();
138  $this->currentPageId = $this->currentPageId ?: ‪self::DEFAULT_BACKEND_STORAGE_PID;
139 
141  }
142 
148  protected function ‪getCurrentPageIdFromGetPostData()
149  {
150  return (int)GeneralUtility::_GP('id');
151  }
152 
158  protected function ‪getCurrentPageIdFromCurrentSiteRoot()
159  {
160  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
161  ->getQueryBuilderForTable('pages');
162 
163  $queryBuilder
164  ->getRestrictions()
165  ->removeAll()
166  ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
167  ->add(GeneralUtility::makeInstance(HiddenRestriction::class));
168 
169  $rootPage = $queryBuilder
170  ->select('uid')
171  ->from('pages')
172  ->where(
173  $queryBuilder->expr()->eq('is_siteroot', $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT)),
174  $queryBuilder->expr()->eq('sys_language_uid', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT))
175  )
176  ->orderBy('sorting')
177  ->execute()
178  ->fetch();
179 
180  if (empty($rootPage)) {
181  return 0;
182  }
183 
184  return (int)$rootPage['uid'];
185  }
186 
192  protected function ‪getCurrentPageIdFromRootTemplate()
193  {
194  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
195  ->getQueryBuilderForTable('sys_template');
196 
197  $queryBuilder
198  ->getRestrictions()
199  ->removeAll()
200  ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
201  ->add(GeneralUtility::makeInstance(HiddenRestriction::class));
202 
203  $rootTemplate = $queryBuilder
204  ->select('pid')
205  ->from('sys_template')
206  ->where(
207  $queryBuilder->expr()->eq('root', $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT))
208  )
209  ->orderBy('crdate')
210  ->execute()
211  ->fetch();
212 
213  if (empty($rootTemplate)) {
214  return 0;
215  }
216 
217  return (int)$rootTemplate['pid'];
218  }
219 
225  public function ‪getDefaultBackendStoragePid()
226  {
227  return $this->‪getCurrentPageId();
228  }
229 
238  protected function ‪getContextSpecificFrameworkConfiguration(array $frameworkConfiguration)
239  {
240  if (!isset($frameworkConfiguration['mvc']['requestHandlers'])) {
241  $frameworkConfiguration['mvc']['requestHandlers'] = [
242  FrontendRequestHandler::class => FrontendRequestHandler::class,
243  BackendRequestHandler::class => BackendRequestHandler::class
244  ];
245  }
246  return $frameworkConfiguration;
247  }
248 
256  protected function ‪getRecursiveStoragePids($storagePid, $recursionDepth = 0)
257  {
258  if ($recursionDepth <= 0) {
259  return $storagePid;
260  }
261 
262  $recursiveStoragePids = '';
263  $storagePids = GeneralUtility::intExplode(',', $storagePid);
264  $permsClause = $this->‪getBackendUser()->getPagePermsClause(‪Permission::PAGE_SHOW);
265  $queryGenerator = GeneralUtility::makeInstance(QueryGenerator::class);
266  foreach ($storagePids as $startPid) {
267  $pids = $queryGenerator->getTreeList($startPid, $recursionDepth, 0, $permsClause);
268  if ((string)$pids !== '') {
269  $recursiveStoragePids .= $pids . ',';
270  }
271  }
272 
273  return rtrim($recursiveStoragePids, ',');
274  }
275 
279  protected function ‪getBackendUser()
280  {
281  return ‪$GLOBALS['BE_USER'];
282  }
283 }
‪TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction
Definition: HiddenRestriction.php:25
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\$pluginName
‪string $pluginName
Definition: AbstractConfigurationManager.php:56
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager\getBackendUser
‪TYPO3 CMS Core Authentication BackendUserAuthentication getBackendUser()
Definition: BackendConfigurationManager.php:277
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager
Definition: BackendConfigurationManager.php:34
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager\getCurrentPageId
‪int getCurrentPageId()
Definition: BackendConfigurationManager.php:128
‪TYPO3\CMS\Core\Utility\RootlineUtility
Definition: RootlineUtility.php:36
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager\getCurrentPageIdFromGetPostData
‪int getCurrentPageIdFromGetPostData()
Definition: BackendConfigurationManager.php:146
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager\getCurrentPageIdFromRootTemplate
‪int getCurrentPageIdFromRootTemplate()
Definition: BackendConfigurationManager.php:190
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager\$currentPageId
‪int $currentPageId
Definition: BackendConfigurationManager.php:42
‪TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule
‪static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
Definition: ArrayUtility.php:614
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager
Definition: AbstractConfigurationManager.php:22
‪TYPO3\CMS\Core\Database\QueryGenerator
Definition: QueryGenerator.php:33
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:23
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager\getTypoScriptSetup
‪array getTypoScriptSetup()
Definition: BackendConfigurationManager.php:49
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager\getCurrentPageIdFromCurrentSiteRoot
‪int getCurrentPageIdFromCurrentSiteRoot()
Definition: BackendConfigurationManager.php:156
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager\getContextSpecificFrameworkConfiguration
‪array getContextSpecificFrameworkConfiguration(array $frameworkConfiguration)
Definition: BackendConfigurationManager.php:236
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager\getRecursiveStoragePids
‪string getRecursiveStoragePids($storagePid, $recursionDepth=0)
Definition: BackendConfigurationManager.php:254
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_SHOW
‪const PAGE_SHOW
Definition: Permission.php:32
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager\$typoScriptSetupCache
‪array $typoScriptSetupCache
Definition: BackendConfigurationManager.php:37
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager\getPluginConfiguration
‪array getPluginConfiguration($extensionName, $pluginName=null)
Definition: BackendConfigurationManager.php:85
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager\getSwitchableControllerActions
‪array getSwitchableControllerActions($extensionName, $pluginName)
Definition: BackendConfigurationManager.php:113
‪TYPO3\CMS\Extbase\Mvc\Web\BackendRequestHandler
Definition: BackendRequestHandler.php:24
‪TYPO3\CMS\Core\TypoScript\TemplateService
Definition: TemplateService.php:50
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:23
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
Definition: DeletedRestriction.php:26
‪TYPO3\CMS\Extbase\Mvc\Web\FrontendRequestHandler
Definition: FrontendRequestHandler.php:22
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Extbase\Configuration
Definition: AbstractConfigurationManager.php:2
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager\getDefaultBackendStoragePid
‪string getDefaultBackendStoragePid()
Definition: BackendConfigurationManager.php:223
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\$extensionName
‪string $extensionName
Definition: AbstractConfigurationManager.php:50
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\DEFAULT_BACKEND_STORAGE_PID
‪const DEFAULT_BACKEND_STORAGE_PID
Definition: AbstractConfigurationManager.php:26