TYPO3  7.6
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  */
16 
21 {
27  protected $queryGenerator;
28 
32  protected $typoScriptSetupCache = array();
33 
38  protected $currentPageId;
39 
43  public function injectQueryGenerator(\TYPO3\CMS\Core\Database\QueryGenerator $queryGenerator)
44  {
45  $this->queryGenerator = $queryGenerator;
46  }
47 
53  public function getTypoScriptSetup()
54  {
55  $pageId = $this->getCurrentPageId();
56 
57  if (!array_key_exists($pageId, $this->typoScriptSetupCache)) {
59  $template = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\TemplateService::class);
60  // do not log time-performance information
61  $template->tt_track = 0;
62  // Explicitly trigger processing of extension static files
63  $template->setProcessExtensionStatics(true);
64  $template->init();
65  // Get the root line
66  $rootline = array();
67  if ($pageId > 0) {
69  $sysPage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\PageRepository::class);
70  // Get the rootline for the current page
71  $rootline = $sysPage->getRootLine($pageId, '', true);
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 
90  {
91  $setup = $this->getTypoScriptSetup();
92  $pluginConfiguration = array();
93  if (is_array($setup['module.']['tx_' . strtolower($extensionName) . '.'])) {
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 . '.'])) {
99  $overruleConfiguration = $this->typoScriptService->convertTypoScriptArrayToPlainArray($setup['module.']['tx_' . $pluginSignature . '.']);
100  \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($pluginConfiguration, $overruleConfiguration);
101  }
102  }
103  return $pluginConfiguration;
104  }
105 
118  {
119  $switchableControllerActions = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['modules'][$pluginName]['controllers'];
120  if (!is_array($switchableControllerActions)) {
121  $switchableControllerActions = array();
122  }
123  return $switchableControllerActions;
124  }
125 
132  protected function getCurrentPageId()
133  {
134  if ($this->currentPageId !== null) {
135  return $this->currentPageId;
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 
142  return $this->currentPageId;
143  }
144 
150  protected function getCurrentPageIdFromGetPostData()
151  {
152  return (int)\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('id');
153  }
154 
161  {
162  $rootPage = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
163  'uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', 'sorting'
164  );
165  if (empty($rootPage)) {
166  return 0;
167  }
168 
169  return (int)$rootPage['uid'];
170  }
171 
177  protected function getCurrentPageIdFromRootTemplate()
178  {
179  $rootTemplate = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
180  'pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', 'crdate'
181  );
182  if (empty($rootTemplate)) {
183  return 0;
184  }
185 
186  return (int)$rootTemplate['pid'];
187  }
188 
194  public function getDefaultBackendStoragePid()
195  {
196  return $this->getCurrentPageId();
197  }
198 
207  protected function getContextSpecificFrameworkConfiguration(array $frameworkConfiguration)
208  {
209  if (!isset($frameworkConfiguration['mvc']['requestHandlers'])) {
210  $frameworkConfiguration['mvc']['requestHandlers'] = array(
211  \TYPO3\CMS\Extbase\Mvc\Web\FrontendRequestHandler::class => \TYPO3\CMS\Extbase\Mvc\Web\FrontendRequestHandler::class,
212  \TYPO3\CMS\Extbase\Mvc\Web\BackendRequestHandler::class => \TYPO3\CMS\Extbase\Mvc\Web\BackendRequestHandler::class
213  );
214  }
215  return $frameworkConfiguration;
216  }
217 
218 
226  protected function getRecursiveStoragePids($storagePid, $recursionDepth = 0)
227  {
228  if ($recursionDepth <= 0) {
229  return $storagePid;
230  }
231 
232  $recursiveStoragePids = '';
233  $storagePids = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $storagePid);
234  foreach ($storagePids as $startPid) {
235  $pids = $this->queryGenerator->getTreeList($startPid, $recursionDepth, 0, 1);
236  if ((string)$pids !== '') {
237  $recursiveStoragePids .= $pids . ',';
238  }
239  }
240 
241  return rtrim($recursiveStoragePids, ',');
242  }
243 }