[TASK] Decouple adminPanel from frontend
[Packages/TYPO3.CMS.git] / typo3 / sysext / adminpanel / Classes / Modules / CacheModule.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\Type\Bitmask\Permission;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22 use TYPO3\CMS\Fluid\View\StandaloneView;
23 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
24
25 class CacheModule extends AbstractModule
26 {
27 /**
28 * Creates the content for the "cache" section ("module") of the Admin Panel
29 *
30 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
31 */
32 public function getContent(): string
33 {
34 $view = GeneralUtility::makeInstance(StandaloneView::class);
35 $templateNameAndPath = $this->extResources . '/Templates/Modules/Cache.html';
36 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templateNameAndPath));
37 $view->setPartialRootPaths([$this->extResources . '/Partials']);
38
39 $view->assignMultiple([
40 'isEnabled' => $this->getBackendUser()->uc['TSFE_adminConfig']['display_cache'],
41 'noCache' => $this->getBackendUser()->uc['TSFE_adminConfig']['cache_noCache'],
42 'cacheLevels' => $this->getBackendUser()->uc['TSFE_adminConfig']['cache_clearCacheLevels'],
43 'currentId' => $this->getTypoScriptFrontendController()->id
44 ]);
45
46 return $view->render();
47 }
48
49 /**
50 * @inheritdoc
51 */
52 public function getIdentifier(): string
53 {
54 return 'cache';
55 }
56
57 /**
58 * @inheritdoc
59 */
60 public function getLabel(): string
61 {
62 $locallangFileAndPath = 'LLL:' . $this->extResources . '/Language/locallang_cache.xlf:module.label';
63 return $this->getLanguageService()->sL($locallangFileAndPath);
64 }
65
66 /**
67 * @inheritdoc
68 */
69 public function initializeModule(ServerRequest $request): void
70 {
71 if ($this->getConfigurationOption('noCache')) {
72 $this->getTypoScriptFrontendController()->set_no_cache('Admin Panel: No Caching', true);
73 }
74 }
75
76 /**
77 * Clear cache on saving if requested
78 *
79 * @param array $input
80 */
81 public function onSubmit(array $input): void
82 {
83 if (($input['action']['clearCache'] ?? false) || isset($input['preview_showFluidDebug'])) {
84 $theStartId = (int)$input['cache_clearCacheId'];
85 $this->getTypoScriptFrontendController()
86 ->clearPageCacheContent_pidList(
87 $this->getBackendUser()->extGetTreeList(
88 $theStartId,
89 (int)$this->getConfigurationOption('clearCacheLevels'),
90 0,
91 $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW)
92 ) . $theStartId
93 );
94 }
95 }
96
97 /**
98 * @inheritdoc
99 */
100 public function showFormSubmitButton(): bool
101 {
102 return true;
103 }
104
105 /**
106 * @return TypoScriptFrontendController
107 */
108 protected function getTypoScriptFrontendController(): TypoScriptFrontendController
109 {
110 return $GLOBALS['TSFE'];
111 }
112 }