2 namespace TYPO3\CMS\Extbase\Configuration
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Core\Database\ConnectionPool
;
18 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
;
19 use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction
;
20 use TYPO3\CMS\Core\Database\QueryGenerator
;
21 use TYPO3\CMS\Core\Type\Bitmask\Permission
;
22 use TYPO3\CMS\Core\TypoScript\TemplateService
;
23 use TYPO3\CMS\Core\Utility\ArrayUtility
;
24 use TYPO3\CMS\Core\Utility\GeneralUtility
;
25 use TYPO3\CMS\Extbase\Mvc\Web\BackendRequestHandler
;
26 use TYPO3\CMS\Extbase\Mvc\Web\FrontendRequestHandler
;
27 use TYPO3\CMS\Frontend\Page\PageRepository
;
30 * A general purpose configuration manager used in backend mode.
32 class BackendConfigurationManager
extends AbstractConfigurationManager
37 protected $typoScriptSetupCache = [];
40 * stores the current page ID
43 protected $currentPageId;
46 * Returns TypoScript Setup array from current Environment.
48 * @return array the raw TypoScript setup
50 public function getTypoScriptSetup()
52 $pageId = $this->getCurrentPageId();
54 if (!array_key_exists($pageId, $this->typoScriptSetupCache
)) {
55 /** @var $template TemplateService */
56 $template = GeneralUtility
::makeInstance(TemplateService
::class);
57 // do not log time-performance information
58 $template->tt_track
= 0;
59 // Explicitly trigger processing of extension static files
60 $template->setProcessExtensionStatics(true);
65 /** @var $sysPage PageRepository */
66 $sysPage = GeneralUtility
::makeInstance(PageRepository
::class);
67 // Get the rootline for the current page
68 $rootline = $sysPage->getRootLine($pageId, '', true);
70 // This generates the constants/config + hierarchy info for the template.
71 $template->runThroughTemplates($rootline, 0);
72 $template->generateConfig();
73 $this->typoScriptSetupCache
[$pageId] = $template->setup
;
75 return $this->typoScriptSetupCache
[$pageId];
79 * Returns the TypoScript configuration found in module.tx_yourextension_yourmodule
80 * merged with the global configuration of your extension from module.tx_yourextension
82 * @param string $extensionName
83 * @param string $pluginName in BE mode this is actually the module signature. But we're using it just like the plugin name in FE
86 protected function getPluginConfiguration($extensionName, $pluginName = null)
88 $setup = $this->getTypoScriptSetup();
89 $pluginConfiguration = [];
90 if (is_array($setup['module.']['tx_' . strtolower($extensionName) . '.'] ??
false)) {
91 $pluginConfiguration = $this->typoScriptService
->convertTypoScriptArrayToPlainArray($setup['module.']['tx_' . strtolower($extensionName) . '.']);
93 if ($pluginName !== null) {
94 $pluginSignature = strtolower($extensionName . '_' . $pluginName);
95 if (is_array($setup['module.']['tx_' . $pluginSignature . '.'] ??
false)) {
96 $overruleConfiguration = $this->typoScriptService
->convertTypoScriptArrayToPlainArray($setup['module.']['tx_' . $pluginSignature . '.']);
97 ArrayUtility
::mergeRecursiveWithOverrule($pluginConfiguration, $overruleConfiguration);
100 return $pluginConfiguration;
104 * Returns the configured controller/action pairs of the specified module in the format
106 * 'Controller1' => array('action1', 'action2'),
107 * 'Controller2' => array('action3', 'action4')
110 * @param string $extensionName
111 * @param string $pluginName in BE mode this is actually the module signature. But we're using it just like the plugin name in FE
114 protected function getSwitchableControllerActions($extensionName, $pluginName)
116 $switchableControllerActions = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['modules'][$pluginName]['controllers'] ??
false;
117 if (!is_array($switchableControllerActions)) {
118 $switchableControllerActions = [];
120 return $switchableControllerActions;
124 * Returns the page uid of the current page.
125 * If no page is selected, we'll return the uid of the first root page.
127 * @return int current page id. If no page is selected current root page id is returned
129 protected function getCurrentPageId()
131 if ($this->currentPageId
!== null) {
132 return $this->currentPageId
;
135 $this->currentPageId
= $this->getCurrentPageIdFromGetPostData() ?
: $this->getCurrentPageIdFromCurrentSiteRoot();
136 $this->currentPageId
= $this->currentPageId ?
: $this->getCurrentPageIdFromRootTemplate();
137 $this->currentPageId
= $this->currentPageId ?
: self
::DEFAULT_BACKEND_STORAGE_PID
;
139 return $this->currentPageId
;
143 * Gets the current page ID from the GET/POST data.
145 * @return int the page UID, will be 0 if none has been set
147 protected function getCurrentPageIdFromGetPostData()
149 return (int)GeneralUtility
::_GP('id');
153 * Gets the current page ID from the first site root in tree.
155 * @return int the page UID, will be 0 if none has been set
157 protected function getCurrentPageIdFromCurrentSiteRoot()
159 $queryBuilder = GeneralUtility
::makeInstance(ConnectionPool
::class)
160 ->getQueryBuilderForTable('pages');
165 ->add(GeneralUtility
::makeInstance(DeletedRestriction
::class))
166 ->add(GeneralUtility
::makeInstance(HiddenRestriction
::class));
168 $rootPage = $queryBuilder
172 $queryBuilder->expr()->eq('is_siteroot', $queryBuilder->createNamedParameter(1, \PDO
::PARAM_INT
))
178 if (empty($rootPage)) {
182 return (int)$rootPage['uid'];
186 * Gets the current page ID from the first created root template.
188 * @return int the page UID, will be 0 if none has been set
190 protected function getCurrentPageIdFromRootTemplate()
192 $queryBuilder = GeneralUtility
::makeInstance(ConnectionPool
::class)
193 ->getQueryBuilderForTable('sys_template');
198 ->add(GeneralUtility
::makeInstance(DeletedRestriction
::class))
199 ->add(GeneralUtility
::makeInstance(HiddenRestriction
::class));
201 $rootTemplate = $queryBuilder
203 ->from('sys_template')
205 $queryBuilder->expr()->eq('root', $queryBuilder->createNamedParameter(1, \PDO
::PARAM_INT
))
211 if (empty($rootTemplate)) {
215 return (int)$rootTemplate['pid'];
219 * Returns the default backend storage pid
223 public function getDefaultBackendStoragePid()
225 return $this->getCurrentPageId();
229 * We need to set some default request handler if the framework configuration
230 * could not be loaded; to make sure Extbase also works in Backend modules
233 * @param array $frameworkConfiguration
236 protected function getContextSpecificFrameworkConfiguration(array $frameworkConfiguration)
238 if (!isset($frameworkConfiguration['mvc']['requestHandlers'])) {
239 $frameworkConfiguration['mvc']['requestHandlers'] = [
240 FrontendRequestHandler
::class => FrontendRequestHandler
::class,
241 BackendRequestHandler
::class => BackendRequestHandler
::class
244 return $frameworkConfiguration;
248 * Returns a comma separated list of storagePid that are below a certain storage pid.
250 * @param string $storagePid Storage PID to start at; multiple PIDs possible as comma-separated list
251 * @param int $recursionDepth Maximum number of levels to search, 0 to disable recursive lookup
252 * @return string storage PIDs
254 protected function getRecursiveStoragePids($storagePid, $recursionDepth = 0)
256 if ($recursionDepth <= 0) {
260 $recursiveStoragePids = '';
261 $storagePids = GeneralUtility
::intExplode(',', $storagePid);
262 $permsClause = $this->getBackendUser()->getPagePermsClause(Permission
::PAGE_SHOW
);
263 $queryGenerator = GeneralUtility
::makeInstance(QueryGenerator
::class);
264 foreach ($storagePids as $startPid) {
265 $pids = $queryGenerator->getTreeList($startPid, $recursionDepth, 0, $permsClause);
266 if ((string)$pids !== '') {
267 $recursiveStoragePids .= $pids . ',';
271 return rtrim($recursiveStoragePids, ',');
275 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
277 protected function getBackendUser()
279 return $GLOBALS['BE_USER'];