‪TYPO3CMS  11.5
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 
31 
37 {
41  protected ‪$typoScriptSetupCache = [];
42 
47  protected ‪$currentPageId;
48 
54  public function ‪getTypoScriptSetup(): array
55  {
56  $pageId = $this->‪getCurrentPageId();
57 
58  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, ‪Connection::PARAM_INT)),
176  $queryBuilder->expr()->eq('sys_language_uid', $queryBuilder->createNamedParameter(0, ‪Connection::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, ‪Connection::PARAM_INT)),
179  $queryBuilder->expr()->eq('t3ver_wsid', $queryBuilder->createNamedParameter(0, ‪Connection::PARAM_INT))
180  )
181  ->orderBy('sorting')
182  ->executeQuery()
183  ->fetchAssociative();
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, ‪Connection::PARAM_INT))
213  )
214  ->orderBy('crdate')
215  ->executeQuery()
216  ->fetchAssociative();
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, int $recursionDepth = 0): array
257  {
258  if ($recursionDepth <= 0) {
259  return $storagePids;
260  }
262  $this->‪getBackendUser()->getPagePermsClause(‪Permission::PAGE_SHOW)
263  );
264  $recursiveStoragePids = [];
265  foreach ($storagePids as $startPid) {
266  $startPid = abs($startPid);
267  $recursiveStoragePids = array_merge(
268  $recursiveStoragePids,
269  [ $startPid ],
270  $this->‪getPageChildrenRecursive($startPid, $recursionDepth, 0, $permsClause)
271  );
272  }
273  return array_unique($recursiveStoragePids);
274  }
275 
285  protected function ‪getPageChildrenRecursive(int $pid, int $depth, int $begin, string $permsClause): array
286  {
287  $children = [];
288  if ($pid && $depth > 0) {
289  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
290  $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
291  $statement = $queryBuilder->select('uid')
292  ->from('pages')
293  ->where(
294  $queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pid, ‪Connection::PARAM_INT)),
295  $queryBuilder->expr()->eq('sys_language_uid', 0),
296  $permsClause
297  )
298  ->orderBy('uid')
299  ->executeQuery();
300  while ($row = $statement->fetchAssociative()) {
301  if ($begin <= 0) {
302  $children[] = (int)$row['uid'];
303  }
304  if ($depth > 1) {
305  $theSubList = $this->‪getPageChildrenRecursive((int)$row['uid'], $depth - 1, $begin - 1, $permsClause);
306  $children = array_merge($children, $theSubList);
307  }
308  }
309  }
310  return $children;
311  }
312 
316  protected function ‪getBackendUser(): ‪BackendUserAuthentication
317  {
318  return ‪$GLOBALS['BE_USER'];
319  }
320 }
‪TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction
Definition: HiddenRestriction.php:27
‪TYPO3\CMS\Core\Database\Connection\PARAM_INT
‪const PARAM_INT
Definition: Connection.php:49
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\$pluginName
‪string $pluginName
Definition: AbstractConfigurationManager.php:62
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager
Definition: BackendConfigurationManager.php:37
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager\getCurrentPageId
‪int getCurrentPageId()
Definition: BackendConfigurationManager.php:130
‪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:38
‪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:45
‪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\BackendConfigurationManager\getPageChildrenRecursive
‪int[] getPageChildrenRecursive(int $pid, int $depth, int $begin, string $permsClause)
Definition: BackendConfigurationManager.php:283
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager
Definition: AbstractConfigurationManager.php:34
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:26
‪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:52
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager\getRecursiveStoragePids
‪int[] getRecursiveStoragePids(array $storagePids, int $recursionDepth=0)
Definition: BackendConfigurationManager.php:254
‪TYPO3\CMS\Core\Database\Query\QueryHelper
Definition: QueryHelper.php:32
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: BackendConfigurationManager.php:314
‪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:35
‪TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager\$typoScriptSetupCache
‪array $typoScriptSetupCache
Definition: BackendConfigurationManager.php:40
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:38
‪TYPO3\CMS\Core\TypoScript\TemplateService
Definition: TemplateService.php:46
‪TYPO3\CMS\Core\Database\Query\QueryHelper\stripLogicalOperatorPrefix
‪static string stripLogicalOperatorPrefix(string $constraint)
Definition: QueryHelper.php:171
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:24
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
Definition: DeletedRestriction.php:28
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪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:56
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\DEFAULT_BACKEND_STORAGE_PID
‪const DEFAULT_BACKEND_STORAGE_PID
Definition: AbstractConfigurationManager.php:38