[FEATURE] Add SQL Logging to AdminPanel
[Packages/TYPO3.CMS.git] / typo3 / sysext / adminpanel / Classes / Controller / AjaxController.php
1 <?php
2 declare(strict_types = 1);
3
4 namespace TYPO3\CMS\Adminpanel\Controller;
5
6 /*
7 * This file is part of the TYPO3 CMS project.
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 use Psr\Http\Message\ServerRequestInterface;
20 use TYPO3\CMS\Adminpanel\Service\ConfigurationService;
21 use TYPO3\CMS\Adminpanel\Service\ModuleLoader;
22 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
23 use TYPO3\CMS\Core\Http\JsonResponse;
24 use TYPO3\CMS\Core\Utility\GeneralUtility;
25
26 /**
27 * Admin Panel Ajax Controller - Route endpoint for ajax actions
28 *
29 * @internal
30 */
31 class AjaxController
32 {
33 /**
34 * @var array
35 */
36 protected $adminPanelModuleConfiguration;
37
38 /**
39 * @var ModuleLoader
40 */
41 protected $moduleLoader;
42
43 /**
44 * @var ConfigurationService
45 */
46 private $configurationService;
47
48 /**
49 * @param ConfigurationService $configurationService
50 * @param ModuleLoader $moduleLoader
51 */
52 public function __construct(ConfigurationService $configurationService = null, ModuleLoader $moduleLoader = null)
53 {
54 $this->configurationService = $configurationService
55 ??
56 GeneralUtility::makeInstance(ConfigurationService::class);
57 $this->adminPanelModuleConfiguration = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules'] ?? [];
58 $this->moduleLoader = $moduleLoader ?? GeneralUtility::makeInstance(ModuleLoader::class);
59 }
60
61 /**
62 * Save adminPanel data
63 *
64 * @param ServerRequestInterface $request
65 * @return JsonResponse
66 */
67 public function saveDataAction(ServerRequestInterface $request): JsonResponse
68 {
69 $this->configurationService->saveConfiguration(
70 $this->moduleLoader->validateSortAndInitializeModules($this->adminPanelModuleConfiguration),
71 $request
72 );
73 return new JsonResponse(['success' => true]);
74 }
75
76 /**
77 * Toggle admin panel active state via UC
78 *
79 * @return JsonResponse
80 */
81 public function toggleActiveState(): JsonResponse
82 {
83 $backendUser = $this->getBackendUser();
84 if ($backendUser->uc['AdminPanel']['display_top'] ?? false) {
85 $backendUser->uc['AdminPanel']['display_top'] = false;
86 } else {
87 $backendUser->uc['AdminPanel']['display_top'] = true;
88 }
89 $backendUser->writeUC();
90 return new JsonResponse(['success' => true]);
91 }
92
93 /**
94 * Returns the current BE user.
95 *
96 * @return BackendUserAuthentication
97 */
98 protected function getBackendUser(): BackendUserAuthentication
99 {
100 return $GLOBALS['BE_USER'];
101 }
102 }