[TASK] Use ModuleTemplate API for ext:lowlevel
[Packages/TYPO3.CMS.git] / typo3 / sysext / lowlevel / Classes / View / ConfigurationView.php
1 <?php
2 namespace TYPO3\CMS\Lowlevel\View;
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
17 use Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
19 use TYPO3\CMS\Backend\Module\BaseScriptClass;
20 use TYPO3\CMS\Backend\Template\Components\ButtonBar;
21 use TYPO3\CMS\Backend\Template\ModuleTemplate;
22 use TYPO3\CMS\Backend\Utility\BackendUtility;
23 use TYPO3\CMS\Core\Utility\ArrayUtility;
24 use TYPO3\CMS\Core\Utility\GeneralUtility;
25 use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
26 use TYPO3\CMS\Fluid\View\StandaloneView;
27 use TYPO3\CMS\Lowlevel\Utility\ArrayBrowser;
28
29 /**
30 * Script class for the Config module
31 */
32 class ConfigurationView extends BaseScriptClass
33 {
34 /**
35 * @var StandaloneView
36 */
37 protected $view;
38
39 /**
40 * The name of the module
41 *
42 * @var string
43 */
44 protected $moduleName = 'system_config';
45
46 /**
47 * ModuleTemplate Container
48 *
49 * @var ModuleTemplate
50 */
51 protected $moduleTemplate;
52
53 /**
54 * Constructor
55 */
56 public function __construct()
57 {
58 $this->view = GeneralUtility::makeInstance(StandaloneView::class);
59 $this->view->getRequest()->setControllerExtensionName('lowlevel');
60 }
61
62 /**
63 * Initialization
64 *
65 * @return void
66 */
67 public function init()
68 {
69 $this->menuConfig();
70 $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
71 $this->moduleTemplate->setForm('<form action="" method="post">');
72 }
73
74 /**
75 * Menu Configuration
76 *
77 * @return void
78 */
79 public function menuConfig()
80 {
81 // MENU-ITEMS:
82 // If array, then it's a selector box menu
83 // If empty string it's just a variable, that'll be saved.
84 // Values NOT in this array will not be saved in the settings-array for the module.
85 $this->MOD_MENU = array(
86 'function' => array(
87 0 => LocalizationUtility::translate('typo3ConfVars', 'lowlevel'),
88 1 => LocalizationUtility::translate('tca', 'lowlevel'),
89 2 => LocalizationUtility::translate('tcaDescr', 'lowlevel'),
90 3 => LocalizationUtility::translate('loadedExt', 'lowlevel'),
91 4 => LocalizationUtility::translate('t3services', 'lowlevel'),
92 5 => LocalizationUtility::translate('tbemodules', 'lowlevel'),
93 6 => LocalizationUtility::translate('tbemodulesext', 'lowlevel'),
94 7 => LocalizationUtility::translate('tbeStyles', 'lowlevel'),
95 8 => LocalizationUtility::translate('beUser', 'lowlevel'),
96 9 => LocalizationUtility::translate('usersettings', 'lowlevel')
97 ),
98 'regexsearch' => '',
99 'fixedLgd' => ''
100 );
101 // CLEANSE SETTINGS
102 $this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, GeneralUtility::_GP('SET'), $this->moduleName);
103 }
104
105 /**
106 * Main function
107 *
108 * @return void
109 */
110 public function main()
111 {
112 /** @var ArrayBrowser $arrayBrowser */
113 $arrayBrowser = GeneralUtility::makeInstance(ArrayBrowser::class);
114 $label = $this->MOD_MENU['function'][$this->MOD_SETTINGS['function']];
115 $search_field = GeneralUtility::_GP('search_field');
116
117 $templatePathAndFilename = GeneralUtility::getFileAbsFileName('EXT:lowlevel/Resources/Private/Templates/Backend/Configuration.html');
118 $this->view->setTemplatePathAndFilename($templatePathAndFilename);
119 $this->view->assign('label', $label);
120 $this->view->assign('search_field', $search_field);
121 $this->view->assign('checkbox_checkRegexsearch', BackendUtility::getFuncCheck(0, 'SET[regexsearch]', $this->MOD_SETTINGS['regexsearch'], '', '', 'id="checkRegexsearch"'));
122
123 switch ($this->MOD_SETTINGS['function']) {
124 case 0:
125 $theVar = $GLOBALS['TYPO3_CONF_VARS'];
126 ArrayUtility::naturalKeySortRecursive($theVar);
127 $arrayBrowser->varName = '$TYPO3_CONF_VARS';
128 break;
129 case 1:
130 $theVar = $GLOBALS['TCA'];
131 ArrayUtility::naturalKeySortRecursive($theVar);
132 $arrayBrowser->varName = '$TCA';
133 break;
134 case 2:
135 $theVar = $GLOBALS['TCA_DESCR'];
136 ArrayUtility::naturalKeySortRecursive($theVar);
137 $arrayBrowser->varName = '$TCA_DESCR';
138 break;
139 case 3:
140 $theVar = $GLOBALS['TYPO3_LOADED_EXT'];
141 ArrayUtility::naturalKeySortRecursive($theVar);
142 $arrayBrowser->varName = '$TYPO3_LOADED_EXT';
143 break;
144 case 4:
145 $theVar = $GLOBALS['T3_SERVICES'];
146 ArrayUtility::naturalKeySortRecursive($theVar);
147 $arrayBrowser->varName = '$T3_SERVICES';
148 break;
149 case 5:
150 $theVar = $GLOBALS['TBE_MODULES'];
151 ArrayUtility::naturalKeySortRecursive($theVar);
152 $arrayBrowser->varName = '$TBE_MODULES';
153 break;
154 case 6:
155 $theVar = $GLOBALS['TBE_MODULES_EXT'];
156 ArrayUtility::naturalKeySortRecursive($theVar);
157 $arrayBrowser->varName = '$TBE_MODULES_EXT';
158 break;
159 case 7:
160 $theVar = $GLOBALS['TBE_STYLES'];
161 ArrayUtility::naturalKeySortRecursive($theVar);
162 $arrayBrowser->varName = '$TBE_STYLES';
163 break;
164 case 8:
165 $theVar = $GLOBALS['BE_USER']->uc;
166 ArrayUtility::naturalKeySortRecursive($theVar);
167 $arrayBrowser->varName = '$BE_USER->uc';
168 break;
169 case 9:
170 $theVar = $GLOBALS['TYPO3_USER_SETTINGS'];
171 ArrayUtility::naturalKeySortRecursive($theVar);
172 $arrayBrowser->varName = '$TYPO3_USER_SETTINGS';
173 break;
174 default:
175 $theVar = array();
176 }
177 // Update node:
178 $update = 0;
179 $node = GeneralUtility::_GET('node');
180 // If any plus-signs were clicked, it's registred.
181 if (is_array($node)) {
182 $this->MOD_SETTINGS['node_' . $this->MOD_SETTINGS['function']] = $arrayBrowser->depthKeys($node, $this->MOD_SETTINGS['node_' . $this->MOD_SETTINGS['function']]);
183 $update = 1;
184 }
185 if ($update) {
186 $this->getBackendUser()->pushModuleData($this->moduleName, $this->MOD_SETTINGS);
187 }
188 $arrayBrowser->dontLinkVar = true;
189 $arrayBrowser->depthKeys = $this->MOD_SETTINGS['node_' . $this->MOD_SETTINGS['function']];
190 $arrayBrowser->regexMode = $this->MOD_SETTINGS['regexsearch'];
191 $arrayBrowser->fixedLgd = $this->MOD_SETTINGS['fixedLgd'];
192 $arrayBrowser->searchKeysToo = true;
193
194 // If any POST-vars are send, update the condition array
195 if (GeneralUtility::_POST('search') && trim($search_field)) {
196 $arrayBrowser->depthKeys = $arrayBrowser->getSearchKeys($theVar, '', $search_field, array());
197 }
198 // mask the encryption key to not show it as plaintext in the configuration module
199 if ($theVar == $GLOBALS['TYPO3_CONF_VARS']) {
200 $theVar['SYS']['encryptionKey'] = '***** (length: ' . strlen($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']) . ' characters)';
201 }
202 $tree = $arrayBrowser->tree($theVar, '', '');
203 $this->view->assign('tree', $tree);
204
205 // Setting up the shortcut button for docheader
206 $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
207 // Shortcut
208 if ($this->getBackendUser()->mayMakeShortcut()) {
209 $shortCutButton = $buttonBar->makeFullyRenderedButton()
210 ->setHtmlSource($this->moduleTemplate->makeShortcutIcon('', 'function', $this->moduleName));
211 $buttonBar->addButton($shortCutButton, ButtonBar::BUTTON_POSITION_RIGHT, 2);
212 }
213
214 $this->getModuleMenu();
215
216 $this->content = $this->view->render();
217 }
218
219
220 /**
221 * Injects the request object for the current request or subrequest
222 * Simply calls main() and init() and outputs the content
223 *
224 * @param ServerRequestInterface $request the current request
225 * @param ResponseInterface $response
226 * @return ResponseInterface the response with the content
227 */
228 public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
229 {
230 $GLOBALS['SOBE'] = $this;
231 $this->init();
232 $this->main();
233
234 $this->moduleTemplate->setContent($this->content);
235 $response->getBody()->write($this->moduleTemplate->renderContent());
236 return $response;
237 }
238
239 /**
240 * Print output to browser
241 *
242 * @return void
243 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
244 */
245 public function printContent()
246 {
247 GeneralUtility::logDeprecatedFunction();
248 echo $this->content;
249 }
250
251 /**
252 * Generates the action menu
253 */
254 protected function getModuleMenu()
255 {
256 $menu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
257 $menu->setIdentifier('ConfigurationJumpMenu');
258
259 foreach ($this->MOD_MENU['function'] as $controller => $title) {
260 $item = $menu
261 ->makeMenuItem()
262 ->setHref(
263 BackendUtility::getModuleUrl(
264 $this->moduleName,
265 [
266 'id' => $this->id,
267 'SET' => [
268 'function' => $controller
269 ]
270 ]
271 )
272 )
273 ->setTitle($title);
274 if ($controller === (int)$this->MOD_SETTINGS['function']) {
275 $item->setActive(true);
276 }
277 $menu->addMenuItem($item);
278 }
279 $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
280 }
281 }