TYPO3 CMS  TYPO3_8-7
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 
27 
32 {
36  protected $typoScriptSetupCache = [];
37 
42  protected $currentPageId;
43 
49  public function getTypoScriptSetup()
50  {
51  $pageId = $this->getCurrentPageId();
52 
53  if (!array_key_exists($pageId, $this->typoScriptSetupCache)) {
55  $template = GeneralUtility::makeInstance(TemplateService::class);
56  // do not log time-performance information
57  $template->tt_track = 0;
58  // Explicitly trigger processing of extension static files
59  $template->setProcessExtensionStatics(true);
60  $template->init();
61  // Get the root line
62  $rootline = [];
63  if ($pageId > 0) {
65  $sysPage = GeneralUtility::makeInstance(PageRepository::class);
66  // Get the rootline for the current page
67  $rootline = $sysPage->getRootLine($pageId, '', true);
68  }
69  // This generates the constants/config + hierarchy info for the template.
70  $template->runThroughTemplates($rootline, 0);
71  $template->generateConfig();
72  $this->typoScriptSetupCache[$pageId] = $template->setup;
73  }
74  return $this->typoScriptSetupCache[$pageId];
75  }
76 
86  {
87  $setup = $this->getTypoScriptSetup();
88  $pluginConfiguration = [];
89  if (is_array($setup['module.']['tx_' . strtolower($extensionName) . '.'])) {
90  $pluginConfiguration = $this->typoScriptService->convertTypoScriptArrayToPlainArray($setup['module.']['tx_' . strtolower($extensionName) . '.']);
91  }
92  if ($pluginName !== null) {
93  $pluginSignature = strtolower($extensionName . '_' . $pluginName);
94  if (is_array($setup['module.']['tx_' . $pluginSignature . '.'])) {
95  $overruleConfiguration = $this->typoScriptService->convertTypoScriptArrayToPlainArray($setup['module.']['tx_' . $pluginSignature . '.']);
96  ArrayUtility::mergeRecursiveWithOverrule($pluginConfiguration, $overruleConfiguration);
97  }
98  }
99  return $pluginConfiguration;
100  }
101 
114  {
115  $switchableControllerActions = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['modules'][$pluginName]['controllers'];
116  if (!is_array($switchableControllerActions)) {
117  $switchableControllerActions = [];
118  }
119  return $switchableControllerActions;
120  }
121 
128  protected function getCurrentPageId()
129  {
130  if ($this->currentPageId !== null) {
131  return $this->currentPageId;
132  }
133 
134  $this->currentPageId = $this->getCurrentPageIdFromGetPostData() ?: $this->getCurrentPageIdFromCurrentSiteRoot();
135  $this->currentPageId = $this->currentPageId ?: $this->getCurrentPageIdFromRootTemplate();
136  $this->currentPageId = $this->currentPageId ?: self::DEFAULT_BACKEND_STORAGE_PID;
137 
138  return $this->currentPageId;
139  }
140 
146  protected function getCurrentPageIdFromGetPostData()
147  {
148  return (int)GeneralUtility::_GP('id');
149  }
150 
157  {
158  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
159  ->getQueryBuilderForTable('pages');
160 
161  $queryBuilder
162  ->getRestrictions()
163  ->removeAll()
164  ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
165  ->add(GeneralUtility::makeInstance(HiddenRestriction::class));
166 
167  $rootPage = $queryBuilder
168  ->select('uid')
169  ->from('pages')
170  ->where(
171  $queryBuilder->expr()->eq('is_siteroot', $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT))
172  )
173  ->orderBy('sorting')
174  ->execute()
175  ->fetch();
176 
177  if (empty($rootPage)) {
178  return 0;
179  }
180 
181  return (int)$rootPage['uid'];
182  }
183 
189  protected function getCurrentPageIdFromRootTemplate()
190  {
191  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
192  ->getQueryBuilderForTable('sys_template');
193 
194  $queryBuilder
195  ->getRestrictions()
196  ->removeAll()
197  ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
198  ->add(GeneralUtility::makeInstance(HiddenRestriction::class));
199 
200  $rootTemplate = $queryBuilder
201  ->select('pid')
202  ->from('sys_template')
203  ->where(
204  $queryBuilder->expr()->eq('root', $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT))
205  )
206  ->orderBy('crdate')
207  ->execute()
208  ->fetch();
209 
210  if (empty($rootTemplate)) {
211  return 0;
212  }
213 
214  return (int)$rootTemplate['pid'];
215  }
216 
222  public function getDefaultBackendStoragePid()
223  {
224  return $this->getCurrentPageId();
225  }
226 
235  protected function getContextSpecificFrameworkConfiguration(array $frameworkConfiguration)
236  {
237  if (!isset($frameworkConfiguration['mvc']['requestHandlers'])) {
238  $frameworkConfiguration['mvc']['requestHandlers'] = [
239  FrontendRequestHandler::class => FrontendRequestHandler::class,
240  BackendRequestHandler::class => BackendRequestHandler::class
241  ];
242  }
243  return $frameworkConfiguration;
244  }
245 
253  protected function getRecursiveStoragePids($storagePid, $recursionDepth = 0)
254  {
255  if ($recursionDepth <= 0) {
256  return $storagePid;
257  }
258 
259  $recursiveStoragePids = '';
260  $storagePids = GeneralUtility::intExplode(',', $storagePid);
261  $permsClause = $this->getBackendUser()->getPagePermsClause(1);
262  $queryGenerator = GeneralUtility::makeInstance(QueryGenerator::class);
263  foreach ($storagePids as $startPid) {
264  $pids = $queryGenerator->getTreeList($startPid, $recursionDepth, 0, $permsClause);
265  if ((string)$pids !== '') {
266  $recursiveStoragePids .= $pids . ',';
267  }
268  }
269 
270  return rtrim($recursiveStoragePids, ',');
271  }
272 
276  protected function getBackendUser()
277  {
278  return $GLOBALS['BE_USER'];
279  }
280 }
static intExplode($delimiter, $string, $removeEmptyValues=false, $limit=0)
static makeInstance($className,... $constructorArguments)
static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']