[TASK] Decouple adminPanel from frontend
[Packages/TYPO3.CMS.git] / typo3 / sysext / adminpanel / Classes / Modules / TsDebugModule.php
1 <?php
2 declare(strict_types = 1);
3
4 namespace TYPO3\CMS\Adminpanel\Modules;
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 TYPO3\CMS\Core\Http\ServerRequest;
20 use TYPO3\CMS\Core\TimeTracker\TimeTracker;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22 use TYPO3\CMS\Fluid\View\StandaloneView;
23 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
24
25 /**
26 * Admin Panel TypoScript Debug Module
27 */
28 class TsDebugModule extends AbstractModule
29 {
30 /**
31 * Creates the content for the "tsdebug" section ("module") of the Admin Panel
32 *
33 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
34 */
35 public function getContent(): string
36 {
37 $view = GeneralUtility::makeInstance(StandaloneView::class);
38 $templateNameAndPath = $this->extResources . '/Templates/Modules/TsDebug.html';
39 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templateNameAndPath));
40 $view->setPartialRootPaths([$this->extResources . '/Partials']);
41
42 $tsfeAdminConfig = $this->getBackendUser()->uc['TSFE_adminConfig'];
43 $view->assignMultiple([
44 'isEnabled' => (int)$tsfeAdminConfig['display_tsdebug'],
45 'tree' => (int)$tsfeAdminConfig['tsdebug_tree'],
46 'display' => [
47 'times' => (int)$tsfeAdminConfig['tsdebug_displayTimes'],
48 'messages' => (int)$tsfeAdminConfig['tsdebug_displayMessages'],
49 'content' => (int)$tsfeAdminConfig['tsdebug_displayContent'],
50 ],
51 'trackContentRendering' => (int)$tsfeAdminConfig['tsdebug_LR'],
52 'forceTemplateParsing' => (int)$tsfeAdminConfig['tsdebug_forceTemplateParsing'],
53 'typoScriptLog' => $this->renderTypoScriptLog()
54 ]);
55
56 return $view->render();
57 }
58
59 /**
60 * @inheritdoc
61 */
62 public function getIdentifier(): string
63 {
64 return 'tsdebug';
65 }
66
67 /**
68 * @inheritdoc
69 */
70 public function getLabel(): string
71 {
72 $locallangFileAndPath = 'LLL:' . $this->extResources . '/Language/locallang_tsdebug.xlf:module.label';
73 return $this->getLanguageService()->sL($locallangFileAndPath);
74 }
75
76 /**
77 * @inheritdoc
78 */
79 public function initializeModule(ServerRequest $request): void
80 {
81 $typoScriptFrontend = $this->getTypoScriptFrontendController();
82 $typoScriptFrontend->forceTemplateParsing = (bool)$this->getConfigurationOption('forceTemplateParsing');
83 if ($typoScriptFrontend->forceTemplateParsing) {
84 $typoScriptFrontend->set_no_cache('Admin Panel: Force template parsing', true);
85 }
86 $this->getTimeTracker()->LR = (bool)$this->getConfigurationOption('LR');
87 }
88
89 /**
90 * @inheritdoc
91 */
92 public function showFormSubmitButton(): bool
93 {
94 return true;
95 }
96
97 /**
98 * @return TimeTracker
99 */
100 protected function getTimeTracker(): TimeTracker
101 {
102 return GeneralUtility::makeInstance(TimeTracker::class);
103 }
104
105 /**
106 * @return TypoScriptFrontendController
107 */
108 protected function getTypoScriptFrontendController(): TypoScriptFrontendController
109 {
110 return $GLOBALS['TSFE'];
111 }
112
113 /**
114 * Renders the TypoScript log as string
115 *
116 * @return string
117 */
118 private function renderTypoScriptLog(): string
119 {
120 $timeTracker = $this->getTimeTracker();
121 $timeTracker->printConf['flag_tree'] = $this->getConfigurationOption('tree');
122 $timeTracker->printConf['allTime'] = $this->getConfigurationOption('displayTimes');
123 $timeTracker->printConf['flag_messages'] = $this->getConfigurationOption('displayMessages');
124 $timeTracker->printConf['flag_content'] = $this->getConfigurationOption('displayContent');
125 return $timeTracker->printTSlog();
126 }
127 }