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