2 namespace TYPO3\CMS\Extbase\Configuration
;
4 /***************************************************************
7 * (c) 2010-2013 Extbase Team (http://forge.typo3.org/projects/typo3v4-mvc)
8 * Extbase is a backport of TYPO3 Flow. All credits go to the TYPO3 Flow team.
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 * A copy is found in the textfile GPL.txt and important notices to the license
20 * from the author is found in LICENSE.txt distributed with these scripts.
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
31 * A general purpose configuration manager used in backend mode.
33 class BackendConfigurationManager
extends \TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager
{
36 * @var \TYPO3\CMS\Core\Database\QueryGenerator Needed to recursively fetch a page tree
38 protected $queryGenerator;
41 * Inject query generator
43 * @param \TYPO3\CMS\Core\Database\QueryGenerator $queryGenerator
45 public function injectQueryGenerator(\TYPO3\CMS\Core\Database\QueryGenerator
$queryGenerator) {
46 $this->queryGenerator
= $queryGenerator;
52 protected $typoScriptSetupCache = array();
55 * Returns TypoScript Setup array from current Environment.
57 * @return array the raw TypoScript setup
59 public function getTypoScriptSetup() {
60 $pageId = $this->getCurrentPageId();
62 if (!array_key_exists($pageId, $this->typoScriptSetupCache
)) {
63 /** @var $template \TYPO3\CMS\Core\TypoScript\TemplateService */
64 $template = \TYPO3\CMS\Core\Utility\GeneralUtility
::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\TemplateService');
65 // do not log time-performance information
66 $template->tt_track
= 0;
67 // Explicitly trigger processing of extension static files
68 $template->setProcessExtensionStatics(TRUE);
73 /** @var $sysPage \TYPO3\CMS\Frontend\Page\PageRepository */
74 $sysPage = \TYPO3\CMS\Core\Utility\GeneralUtility
::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
75 // Get the rootline for the current page
76 $rootline = $sysPage->getRootLine($pageId, '', TRUE);
78 // This generates the constants/config + hierarchy info for the template.
79 $template->runThroughTemplates($rootline, 0);
80 $template->generateConfig();
81 $this->typoScriptSetupCache
[$pageId] = $template->setup
;
83 return $this->typoScriptSetupCache
[$pageId];
87 * Returns the TypoScript configuration found in module.tx_yourextension_yourmodule
88 * merged with the global configuration of your extension from module.tx_yourextension
90 * @param string $extensionName
91 * @param string $pluginName in BE mode this is actually the module signature. But we're using it just like the plugin name in FE
94 protected function getPluginConfiguration($extensionName, $pluginName = NULL) {
95 $setup = $this->getTypoScriptSetup();
96 $pluginConfiguration = array();
97 if (is_array($setup['module.']['tx_' . strtolower($extensionName) . '.'])) {
98 $pluginConfiguration = $this->typoScriptService
->convertTypoScriptArrayToPlainArray($setup['module.']['tx_' . strtolower($extensionName) . '.']);
100 if ($pluginName !== NULL) {
101 $pluginSignature = strtolower($extensionName . '_' . $pluginName);
102 if (is_array($setup['module.']['tx_' . $pluginSignature . '.'])) {
103 $pluginConfiguration = \TYPO3\CMS\Core\Utility\GeneralUtility
::array_merge_recursive_overrule($pluginConfiguration, $this->typoScriptService
->convertTypoScriptArrayToPlainArray($setup['module.']['tx_' . $pluginSignature . '.']));
106 return $pluginConfiguration;
110 * Returns the configured controller/action pairs of the specified module in the format
112 * 'Controller1' => array('action1', 'action2'),
113 * 'Controller2' => array('action3', 'action4')
116 * @param string $extensionName
117 * @param string $pluginName in BE mode this is actually the module signature. But we're using it just like the plugin name in FE
120 protected function getSwitchableControllerActions($extensionName, $pluginName) {
121 $switchableControllerActions = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['modules'][$pluginName]['controllers'];
122 if (!is_array($switchableControllerActions)) {
123 $switchableControllerActions = array();
125 return $switchableControllerActions;
129 * Returns the page uid of the current page.
130 * If no page is selected, we'll return the uid of the first root page.
132 * @return integer current page id. If no page is selected current root page id is returned
134 protected function getCurrentPageId() {
135 $pageId = (integer) \TYPO3\CMS\Core\Utility\GeneralUtility
::_GP('id');
139 // get current site root
140 $rootPages = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', '', '1');
141 if (count($rootPages) > 0) {
142 return $rootPages[0]['uid'];
145 $rootTemplates = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', '', '1');
146 if (count($rootTemplates) > 0) {
147 return $rootTemplates[0]['pid'];
150 return self
::DEFAULT_BACKEND_STORAGE_PID
;
154 * Returns the default backend storage pid
158 public function getDefaultBackendStoragePid() {
159 return $this->getCurrentPageId();
163 * We need to set some default request handler if the framework configuration
164 * could not be loaded; to make sure Extbase also works in Backend modules
167 * @param array $frameworkConfiguration
170 protected function getContextSpecificFrameworkConfiguration(array $frameworkConfiguration) {
171 if (!isset($frameworkConfiguration['mvc']['requestHandlers'])) {
172 $frameworkConfiguration['mvc']['requestHandlers'] = array(
173 'TYPO3\\CMS\\Extbase\\Mvc\\Web\\FrontendRequestHandler' => 'TYPO3\\CMS\\Extbase\\Mvc\\Web\\FrontendRequestHandler',
174 'TYPO3\\CMS\\Extbase\\Mvc\\Web\\BackendRequestHandler' => 'TYPO3\\CMS\\Extbase\\Mvc\\Web\\BackendRequestHandler'
177 return $frameworkConfiguration;
182 * Returns a comma separated list of storagePid that are below a certain storage pid.
185 * @param string $storagePid Storage PID to start at; multiple PIDs possible as comma-separated list
186 * @param integer $recursionDepth Maximum number of levels to search, 0 to disable recursive lookup
187 * @return string storage PIDs
189 protected function getRecursiveStoragePids($storagePid, $recursionDepth = 0) {
190 if ($recursionDepth <= 0) {
194 $recursiveStoragePids = '';
195 $storagePids = \TYPO3\CMS\Core\Utility\GeneralUtility
::intExplode(',', $storagePid);
196 foreach ($storagePids as $startPid) {
197 $pids = $this->queryGenerator
->getTreeList($startPid, $recursionDepth, 0, 1);
198 if (strlen($pids) > 0) {
199 $recursiveStoragePids .= $pids . ',';
203 return rtrim($recursiveStoragePids, ',');