TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
BackendConfigurationManager.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Extbase\Configuration;
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  */
20 
25 {
31  protected $queryGenerator;
32 
36  protected $typoScriptSetupCache = [];
37 
42  protected $currentPageId;
43 
47  public function injectQueryGenerator(\TYPO3\CMS\Core\Database\QueryGenerator $queryGenerator)
48  {
49  $this->queryGenerator = $queryGenerator;
50  }
51 
57  public function getTypoScriptSetup()
58  {
59  $pageId = $this->getCurrentPageId();
60 
61  if (!array_key_exists($pageId, $this->typoScriptSetupCache)) {
63  $template = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\TemplateService::class);
64  // do not log time-performance information
65  $template->tt_track = 0;
66  // Explicitly trigger processing of extension static files
67  $template->setProcessExtensionStatics(true);
68  $template->init();
69  // Get the root line
70  $rootline = [];
71  if ($pageId > 0) {
73  $sysPage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\PageRepository::class);
74  // Get the rootline for the current page
75  $rootline = $sysPage->getRootLine($pageId, '', true);
76  }
77  // This generates the constants/config + hierarchy info for the template.
78  $template->runThroughTemplates($rootline, 0);
79  $template->generateConfig();
80  $this->typoScriptSetupCache[$pageId] = $template->setup;
81  }
82  return $this->typoScriptSetupCache[$pageId];
83  }
84 
94  {
95  $setup = $this->getTypoScriptSetup();
96  $pluginConfiguration = [];
97  if (is_array($setup['module.']['tx_' . strtolower($extensionName) . '.'])) {
98  $pluginConfiguration = $this->typoScriptService->convertTypoScriptArrayToPlainArray($setup['module.']['tx_' . strtolower($extensionName) . '.']);
99  }
100  if ($pluginName !== null) {
101  $pluginSignature = strtolower($extensionName . '_' . $pluginName);
102  if (is_array($setup['module.']['tx_' . $pluginSignature . '.'])) {
103  $overruleConfiguration = $this->typoScriptService->convertTypoScriptArrayToPlainArray($setup['module.']['tx_' . $pluginSignature . '.']);
104  \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($pluginConfiguration, $overruleConfiguration);
105  }
106  }
107  return $pluginConfiguration;
108  }
109 
122  {
123  $switchableControllerActions = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['modules'][$pluginName]['controllers'];
124  if (!is_array($switchableControllerActions)) {
125  $switchableControllerActions = [];
126  }
127  return $switchableControllerActions;
128  }
129 
136  protected function getCurrentPageId()
137  {
138  if ($this->currentPageId !== null) {
139  return $this->currentPageId;
140  }
141 
142  $this->currentPageId = $this->getCurrentPageIdFromGetPostData() ?: $this->getCurrentPageIdFromCurrentSiteRoot();
143  $this->currentPageId = $this->currentPageId ?: $this->getCurrentPageIdFromRootTemplate();
144  $this->currentPageId = $this->currentPageId ?: self::DEFAULT_BACKEND_STORAGE_PID;
145 
146  return $this->currentPageId;
147  }
148 
154  protected function getCurrentPageIdFromGetPostData()
155  {
157  }
158 
165  {
166  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
167  ->getQueryBuilderForTable('pages');
168 
169  $queryBuilder
170  ->getRestrictions()
171  ->removeAll()
172  ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
173  ->add(GeneralUtility::makeInstance(HiddenRestriction::class));
174 
175  $rootPage = $queryBuilder
176  ->select('uid')
177  ->from('pages')
178  ->where(
179  $queryBuilder->expr()->eq('is_siteroot', $queryBuilder->createNamedParameter(1, \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()
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()
231  {
232  return $this->getCurrentPageId();
233  }
234 
243  protected function getContextSpecificFrameworkConfiguration(array $frameworkConfiguration)
244  {
245  if (!isset($frameworkConfiguration['mvc']['requestHandlers'])) {
246  $frameworkConfiguration['mvc']['requestHandlers'] = [
247  \TYPO3\CMS\Extbase\Mvc\Web\FrontendRequestHandler::class => \TYPO3\CMS\Extbase\Mvc\Web\FrontendRequestHandler::class,
248  \TYPO3\CMS\Extbase\Mvc\Web\BackendRequestHandler::class => \TYPO3\CMS\Extbase\Mvc\Web\BackendRequestHandler::class
249  ];
250  }
251  return $frameworkConfiguration;
252  }
253 
261  protected function getRecursiveStoragePids($storagePid, $recursionDepth = 0)
262  {
263  if ($recursionDepth <= 0) {
264  return $storagePid;
265  }
266 
267  $recursiveStoragePids = '';
268  $storagePids = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $storagePid);
269  $permsClause = $this->getBackendUser()->getPagePermsClause(1);
270  foreach ($storagePids as $startPid) {
271  $pids = $this->queryGenerator->getTreeList($startPid, $recursionDepth, 0, $permsClause);
272  if ((string)$pids !== '') {
273  $recursiveStoragePids .= $pids . ',';
274  }
275  }
276 
277  return rtrim($recursiveStoragePids, ',');
278  }
279 
283  protected function getBackendUser()
284  {
285  return $GLOBALS['BE_USER'];
286  }
287 }
injectQueryGenerator(\TYPO3\CMS\Core\Database\QueryGenerator $queryGenerator)
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']
static makeInstance($className,...$constructorArguments)
static intExplode($delimiter, $string, $removeEmptyValues=false, $limit=0)