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