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