‪TYPO3CMS  10.4
ConfigurationController.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Container\ContainerInterface;
21 use Psr\Http\Message\ResponseInterface;
22 use Psr\Http\Message\ServerRequestInterface;
39 
45 {
49  protected ‪$container;
50 
51  public function ‪__construct(ContainerInterface ‪$container)
52  {
53  $this->container = ‪$container;
54  }
55 
64  protected ‪$treeSetup = [
65  'confVars' => [
66  'label' => 'typo3ConfVars',
67  'type' => 'global',
68  'globalKey' => 'TYPO3_CONF_VARS',
69  ],
70  'tca' => [
71  'label' => 'tca',
72  'type' => 'global',
73  'globalKey' => 'TCA',
74  ],
75  'tcaDescr' => [
76  'label' => 'tcaDescr',
77  'type' => 'global',
78  'globalKey' => 'TCA_DESCR',
79  ],
80  'services' => [
81  'label' => 't3services',
82  'key' => 'services',
83  'type' => 'global',
84  'globalKey' => 'T3_SERVICES',
85  ],
86  'tbeModules' => [
87  'label' => 'tbemodules',
88  'type' => 'global',
89  'globalKey' => 'TBE_MODULES',
90  ],
91  'tbeModulesExt' => [
92  'label' => 'tbemodulesext',
93  'type' => 'global',
94  'globalKey' => 'TBE_MODULES_EXT',
95  ],
96  'tbeStyles' => [
97  'label' => 'tbeStyles',
98  'type' => 'global',
99  'globalKey' => 'TBE_STYLES',
100  ],
101  'userSettings' => [
102  'label' => 'usersettings',
103  'type' => 'global',
104  'globalKey' => 'TYPO3_USER_SETTINGS',
105  ],
106  'pagesTypes' => [
107  'label' => 'pagesTypes',
108  'type' => 'global',
109  'globalKey' => 'PAGES_TYPES',
110  ],
111  'beUserUc' => [
112  'label' => 'beUser',
113  'type' => 'uc',
114  ],
115  'beUserTsConfig' => [
116  'label' => 'beUserTsConfig',
117  'type' => 'beUserTsConfig',
118  ],
119  'beRoutes' => [
120  'label' => 'routes',
121  'type' => 'routes',
122  ],
123  'httpMiddlewareStacks' => [
124  'label' => 'httpMiddlewareStacks',
125  'type' => 'httpMiddlewareStacks',
126  ],
127  'siteConfiguration' => [
128  'label' => 'siteConfiguration',
129  'type' => 'siteConfiguration',
130  ],
131  'eventListeners' => [
132  'label' => 'eventListeners',
133  'type' => 'eventListeners',
134  ],
135  ];
136 
142  protected ‪$blindedConfigurationOptions = [
143  'TYPO3_CONF_VARS' => [
144  'BE' => [
145  'installToolPassword' => '******'
146  ],
147  'DB' => [
148  'database' => '******',
149  'host' => '******',
150  'password' => '******',
151  'port' => '******',
152  'socket' => '******',
153  'username' => '******',
154  'Connections' => [
155  'Default' => [
156  'dbname' => '******',
157  'host' => '******',
158  'password' => '******',
159  'port' => '******',
160  'user' => '******',
161  'unix_socket' => '******',
162  ],
163  ],
164  ],
165  'HTTP' => [
166  'cert' => '******',
167  'ssl_key' => '******'
168  ],
169  'MAIL' => [
170  'transport_smtp_encrypt' => '******',
171  'transport_smtp_password' => '******',
172  'transport_smtp_server' => '******',
173  'transport_smtp_username' => '******',
174  ],
175  'SYS' => [
176  'encryptionKey' => '******'
177  ],
178  ],
179  ];
180 
190  public function ‪mainAction(ServerRequestInterface $request): ResponseInterface
191  {
193  $this->treeSetup['formYamlConfiguration'] = [
194  'label' => 'formYamlConfiguration',
195  'type' => 'formYamlConfiguration',
196  ];
197  }
198 
199  $backendUser = $this->‪getBackendUser();
200  $languageService = $this->‪getLanguageService();
201 
202  $queryParams = $request->getQueryParams();
203  $postValues = $request->getParsedBody();
204 
205  $moduleState = $backendUser->uc['moduleData']['system_config'] ?? [];
206 
207  // Determine validated tree key and tree detail setup
208  $selectedTreeKey = $this->treeSetup[$queryParams['tree']] ? $queryParams['tree']
209  : ($this->treeSetup[$moduleState['tree']] ? $moduleState['tree'] : key($this->treeSetup));
210  $selectedTreeDetails = $this->treeSetup[$selectedTreeKey];
211  $moduleState['tree'] = $selectedTreeKey;
212 
213  // Search string given or regex search enabled?
214  $searchString = (string)($postValues['searchString'] ? trim($postValues['searchString']) : '');
215  $moduleState['regexSearch'] = (bool)($postValues['regexSearch'] ?? $moduleState['regexSearch'] ?? false);
216 
217  // Prepare main array
218  $sortKeysByName = true;
219  if ($selectedTreeDetails['type'] === 'global') {
220  $globalArrayKey = $selectedTreeDetails['globalKey'];
221  $renderArray = ‪$GLOBALS[$globalArrayKey];
222 
223  // Hook for Processing blindedConfigurationOptions
225 
226  foreach (‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][self::class]['modifyBlindedConfigurationOptions'] ?? [] as $classReference) {
227  $processingObject = GeneralUtility::makeInstance($classReference);
228  ‪$blindedConfigurationOptions = $processingObject->modifyBlindedConfigurationOptions(‪$blindedConfigurationOptions, $this);
229  }
230 
231  if (isset(‪$blindedConfigurationOptions[$globalArrayKey])) {
232  // Prepare blinding for all database connection types
233  foreach (array_keys(‪$GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']) as $connectionName) {
234  if ($connectionName !== 'Default') {
235  ‪$blindedConfigurationOptions['TYPO3_CONF_VARS']['DB']['Connections'][$connectionName] =
236  ‪$blindedConfigurationOptions['TYPO3_CONF_VARS']['DB']['Connections']['Default'];
237  }
238  }
240  $renderArray,
242  );
243  }
244  } elseif ($selectedTreeDetails['type'] === 'beUserTsConfig') {
245  $renderArray = $backendUser->getTSConfig();
246  } elseif ($selectedTreeDetails['type'] === 'uc') {
247  $renderArray = $backendUser->uc;
248  } elseif ($selectedTreeDetails['type'] === 'routes') {
249  $router = GeneralUtility::makeInstance(Router::class);
250  $routes = $router->getRoutes();
251  $renderArray = [];
252  foreach ($routes as $identifier => $route) {
254  $renderArray[$identifier] = [
255  'path' => $route->getPath(),
256  'options' => $route->getOptions()
257  ];
258  }
259  } elseif ($selectedTreeDetails['type'] === 'httpMiddlewareStacks') {
260  // Keep the order of the keys
261  $sortKeysByName = false;
262  $renderArray = [];
263  foreach (['frontend', 'backend'] as $stackName) {
264  // reversing the array allows the admin to read the stack from top to bottom
265  $renderArray[$stackName] = array_reverse((array)$this->container->get($stackName . '.middlewares'));
266  }
267  $renderArray['raw'] = $this->container->get('middlewares');
268  } elseif ($selectedTreeDetails['type'] === 'siteConfiguration') {
269  $renderArray = GeneralUtility::makeInstance(SiteTcaConfiguration::class)->getTca();
270  } elseif ($selectedTreeDetails['type'] === 'eventListeners') {
271  // Keep the order of the keys
272  $sortKeysByName = false;
273  $listenerProvider = $this->container->get(ListenerProvider::class);
274  $renderArray = $listenerProvider->getAllListenerDefinitions();
275  } elseif ($selectedTreeDetails['type'] === 'formYamlConfiguration') {
276  $formConfigurationManager = GeneralUtility::makeInstance(ObjectManager::class)->get(ConfigurationManager::class);
277  $renderArray = $formConfigurationManager->getConfiguration(‪ConfigurationManagerInterface::CONFIGURATION_TYPE_YAML_SETTINGS, 'form');
278  } else {
279  throw new \RuntimeException('Unknown array type "' . $selectedTreeDetails['type'] . '"', 1507845662);
280  }
281  if ($sortKeysByName) {
283  }
284 
285  // Prepare array renderer class, apply search and expand / collapse states
286  $route = GeneralUtility::makeInstance(Router::class)->match(GeneralUtility::_GP('route'));
287  $arrayBrowser = GeneralUtility::makeInstance(ArrayBrowser::class, $route);
288  $arrayBrowser->regexMode = $moduleState['regexSearch'];
289  $node = $queryParams['node'];
290  if ($searchString) {
291  $arrayBrowser->depthKeys = $arrayBrowser->getSearchKeys($renderArray, '', $searchString, []);
292  } elseif (is_array($node)) {
293  $newExpandCollapse = $arrayBrowser->depthKeys($node, $moduleState['node_' . $selectedTreeKey]);
294  $arrayBrowser->depthKeys = $newExpandCollapse;
295  $moduleState['node_' . $selectedTreeKey] = $newExpandCollapse;
296  } else {
297  $arrayBrowser->depthKeys = $moduleState['node_' . $selectedTreeKey] ?? [];
298  }
299 
300  // Store new state
301  $backendUser->uc['moduleData']['system_config'] = $moduleState;
302  $backendUser->writeUC();
303 
304  // Render main body
305  $view = GeneralUtility::makeInstance(StandaloneView::class);
306  $view->getRequest()->setControllerExtensionName('lowlevel');
307  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
308  'EXT:lowlevel/Resources/Private/Templates/Backend/Configuration.html'
309  ));
310  $view->assignMultiple([
311  'treeName' => $selectedTreeDetails['label'],
312  'searchString' => $searchString,
313  'regexSearch' => $moduleState['regexSearch'],
314  'tree' => $arrayBrowser->tree($renderArray, ''),
315  ]);
316 
317  // Prepare module setup
318  $moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
319  $moduleTemplate->setContent($view->render());
320  $moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Lowlevel/ConfigurationView');
321 
322  // Shortcut in doc header
323  $shortcutButton = $moduleTemplate->getDocHeaderComponent()->getButtonBar()->makeShortcutButton();
324  $shortcutButton->setModuleName('system_config')
325  ->setDisplayName($languageService->sL(
326  'LLL:EXT:lowlevel/Resources/Private/Language/locallang.xlf:' . $selectedTreeDetails['label']
327  ))
328  ->setSetVariables(['tree']);
329  $moduleTemplate->getDocHeaderComponent()->getButtonBar()->addButton($shortcutButton);
330 
331  // Main drop down in doc header
332  $menu = $moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
333  $menu->setIdentifier('tree');
334  foreach ($this->treeSetup as $treeKey => $treeDetails) {
335  $menuItem = $menu->makeMenuItem();
337  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
338  $menuItem->setHref((string)$uriBuilder->buildUriFromRoute('system_config', ['tree' => $treeKey]))
339  ->setTitle($languageService->sL(
340  'LLL:EXT:lowlevel/Resources/Private/Language/locallang.xlf:' . $treeDetails['label']
341  ));
342  if ($selectedTreeKey === $treeKey) {
343  $menuItem->setActive(true);
344  }
345  $menu->addMenuItem($menuItem);
346  }
347  $moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
348 
349  return new HtmlResponse($moduleTemplate->renderContent());
350  }
351 
356  protected function ‪getBackendUser()
357  {
358  return ‪$GLOBALS['BE_USER'];
359  }
360 
364  protected function ‪getLanguageService()
365  {
366  return ‪$GLOBALS['LANG'];
367  }
368 }
‪TYPO3\CMS\Backend\Configuration\SiteTcaConfiguration
Definition: SiteTcaConfiguration.php:33
‪TYPO3\CMS\Lowlevel\Controller\ConfigurationController\__construct
‪__construct(ContainerInterface $container)
Definition: ConfigurationController.php:50
‪TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule
‪static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
Definition: ArrayUtility.php:654
‪TYPO3\CMS\Lowlevel\Controller\ConfigurationController\$treeSetup
‪array $treeSetup
Definition: ConfigurationController.php:62
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:43
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:43
‪TYPO3\CMS\Backend\View\ArrayBrowser
Definition: ArrayBrowser.php:31
‪TYPO3\CMS\Lowlevel\Controller\ConfigurationController\$blindedConfigurationOptions
‪array $blindedConfigurationOptions
Definition: ConfigurationController.php:139
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Core\Utility\ArrayUtility\intersectRecursive
‪static array intersectRecursive(array $source, array $mask=[])
Definition: ArrayUtility.php:569
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Lowlevel\Controller
Definition: ConfigurationController.php:18
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:34
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:24
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Lowlevel\Controller\ConfigurationController\getLanguageService
‪LanguageService getLanguageService()
Definition: ConfigurationController.php:361
‪TYPO3\CMS\Lowlevel\Controller\ConfigurationController\mainAction
‪ResponseInterface mainAction(ServerRequestInterface $request)
Definition: ConfigurationController.php:187
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Lowlevel\Controller\ConfigurationController\$container
‪ContainerInterface $container
Definition: ConfigurationController.php:48
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManagerInterface\CONFIGURATION_TYPE_YAML_SETTINGS
‪const CONFIGURATION_TYPE_YAML_SETTINGS
Definition: ConfigurationManagerInterface.php:30
‪TYPO3\CMS\Core\Utility\ArrayUtility\naturalKeySortRecursive
‪static bool naturalKeySortRecursive(array &$array)
Definition: ArrayUtility.php:823
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Routing\Router
Definition: Router.php:34
‪TYPO3\CMS\Lowlevel\Controller\ConfigurationController\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: ConfigurationController.php:353
‪TYPO3\CMS\Core\EventDispatcher\ListenerProvider
Definition: ListenerProvider.php:30
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\isLoaded
‪static bool isLoaded($key)
Definition: ExtensionManagementUtility.php:114
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:28
‪TYPO3\CMS\Lowlevel\Controller\ConfigurationController
Definition: ConfigurationController.php:45
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:26
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManager
Definition: ConfigurationManager.php:34
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManagerInterface
Definition: ConfigurationManagerInterface.php:29