[+BUGFIX] Extbase (Configuration): change the order of methods to determine the curre...
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Configuration / BackendConfigurationManager.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * A general purpose configuration manager used in backend mode.
27 *
28 * @package Extbase
29 * @subpackage Configuration
30 * @version $ID:$
31 */
32 class Tx_Extbase_Configuration_BackendConfigurationManager extends Tx_Extbase_Configuration_AbstractConfigurationManager {
33
34 /**
35 * @var array
36 */
37 protected $typoScriptSetupCache = NULL;
38
39 /**
40 * Returns TypoScript Setup array from current Environment.
41 *
42 * @return array the raw TypoScript setup
43 */
44 public function getTypoScriptSetup() {
45 if ($this->typoScriptSetupCache === NULL) {
46 $template = t3lib_div::makeInstance('t3lib_TStemplate');
47 // do not log time-performance information
48 $template->tt_track = 0;
49 $template->init();
50 // Get the root line
51 $sysPage = t3lib_div::makeInstance('t3lib_pageSelect');
52 // get the rootline for the current page
53 $rootline = $sysPage->getRootLine($this->getCurrentPageId());
54 // This generates the constants/config + hierarchy info for the template.
55 $template->runThroughTemplates($rootline, 0);
56 $template->generateConfig();
57 $this->typoScriptSetupCache = $template->setup;
58 }
59 return $this->typoScriptSetupCache;
60 }
61
62 /**
63 * Returns the TypoScript configuration found in module.tx_yourextension_yourmodule
64 * merged with the global configuration of your extension from module.tx_yourextension
65 *
66 * @param string $extensionName
67 * @param string $pluginName in BE mode this is actually the module signature. But we're using it just like the plugin name in FE
68 * @return array
69 */
70 protected function getPluginConfiguration($extensionName, $pluginName) {
71 $setup = $this->getTypoScriptSetup();
72 $pluginConfiguration = array();
73 if (is_array($setup['module.']['tx_' . strtolower($extensionName) . '.'])) {
74 $pluginConfiguration = Tx_Extbase_Utility_TypoScript::convertTypoScriptArrayToPlainArray($setup['module.']['tx_' . strtolower($extensionName) . '.']);
75 }
76 $pluginSignature = strtolower($extensionName . '_' . $pluginName);
77 if (is_array($setup['module.']['tx_' . $pluginSignature . '.'])) {
78 $pluginConfiguration = t3lib_div::array_merge_recursive_overrule($pluginConfiguration, Tx_Extbase_Utility_TypoScript::convertTypoScriptArrayToPlainArray($setup['module.']['tx_' . $pluginSignature . '.']));
79 }
80 return $pluginConfiguration;
81 }
82
83 /**
84 * Returns the configured controller/action pairs of the specified module in the format
85 * array(
86 * 'Controller1' => array('action1', 'action2'),
87 * 'Controller2' => array('action3', 'action4')
88 * )
89 *
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
92 * @return array
93 */
94 protected function getSwitchableControllerActions($extensionName, $pluginName) {
95 $switchableControllerActions = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['modules'][$pluginName]['controllers'];
96 if (!is_array($switchableControllerActions)) {
97 $switchableControllerActions = array();
98 }
99 return $switchableControllerActions;
100 }
101
102 /**
103 * Returns the page uid of the current page.
104 * If no page is selected, we'll return the uid of the first root page.
105 *
106 * @return integer current page id. If no page is selected current root page id is returned
107 */
108 protected function getCurrentPageId() {
109 $pageId = (integer)t3lib_div::_GP('id');
110 if ($pageId > 0) {
111 return $pageId;
112 }
113
114 // get current site root
115 $rootPages = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', '', '1');
116 if (count($rootPages) > 0) {
117 return $rootPages[0]['uid'];
118 }
119
120 // get root template
121 $rootTemplates = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', '', '1');
122 if (count($rootTemplates) > 0) {
123 return $rootTemplates[0]['pid'];
124 }
125
126 // fallback
127 return self::DEFAULT_BACKEND_STORAGE_PID;
128 }
129
130 /**
131 * We do not want to override anything in the backend.
132 * @return array
133 */
134 protected function getContextSpecificFrameworkConfiguration(array $frameworkConfiguration) {
135 return $frameworkConfiguration;
136 }
137 }
138 ?>