[FEATURE] Refactor AdminPanel API to use composition
[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 Psr\Http\Message\ServerRequestInterface;
20 use TYPO3\CMS\Adminpanel\ModuleApi\AbstractModule;
21 use TYPO3\CMS\Adminpanel\ModuleApi\InitializableInterface;
22 use TYPO3\CMS\Adminpanel\ModuleApi\PageSettingsProviderInterface;
23 use TYPO3\CMS\Backend\Routing\UriBuilder;
24 use TYPO3\CMS\Core\Utility\GeneralUtility;
25 use TYPO3\CMS\Fluid\View\StandaloneView;
26 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
27
28 class CacheModule extends AbstractModule implements PageSettingsProviderInterface, InitializableInterface
29 {
30 /**
31 * @return string
32 */
33 public function getIconIdentifier(): string
34 {
35 return 'apps-toolbar-menu-cache';
36 }
37
38 /**
39 * @return string
40 */
41 public function getPageSettings(): string
42 {
43 $view = GeneralUtility::makeInstance(StandaloneView::class);
44 $templateNameAndPath = 'EXT:adminpanel/Resources/Private/Templates/Modules/Settings/Cache.html';
45 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templateNameAndPath));
46 $view->setPartialRootPaths(['EXT:adminpanel/Resources/Private/Partials']);
47
48 $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
49 $feCacheClear = $this->getBackendUser()->isAdmin() || $this->getBackendUser()->getTSConfig()['options.']['clearCache.']['pages'];
50
51 $view->assignMultiple(
52 [
53 'isEnabled' => $this->getBackendUser()->uc['AdminPanel']['display_cache'],
54 'noCache' => $this->getBackendUser()->uc['AdminPanel']['cache_noCache'],
55 'currentId' => $this->getTypoScriptFrontendController()->id,
56 'clearPageCacheUrl' => $feCacheClear ? (string)$uriBuilder->buildUriFromRoute('tce_db', ['cacheCmd' => 'pages']) : '',
57 'clearCurrentPageCacheUrl' => (string)$uriBuilder->buildUriFromRoute(
58 'tce_db',
59 [
60 'cacheCmd' => $this->getTypoScriptFrontendController()->id,
61 ]
62 ),
63 ]
64 );
65
66 return $view->render();
67 }
68
69 /**
70 * @inheritdoc
71 */
72 public function getIdentifier(): string
73 {
74 return 'cache';
75 }
76
77 /**
78 * @inheritdoc
79 */
80 public function getLabel(): string
81 {
82 $locallangFileAndPath = 'LLL:EXT:adminpanel/Resources/Private/Language/locallang_cache.xlf:module.label';
83 return $this->getLanguageService()->sL($locallangFileAndPath);
84 }
85
86 /**
87 * @inheritdoc
88 */
89 public function initializeModule(ServerRequestInterface $request): void
90 {
91 if ($this->configurationService->getConfigurationOption('cache', 'noCache')) {
92 $this->getTypoScriptFrontendController()->set_no_cache('Admin Panel: No Caching', true);
93 }
94 }
95
96 /**
97 * @return TypoScriptFrontendController
98 */
99 protected function getTypoScriptFrontendController(): TypoScriptFrontendController
100 {
101 return $GLOBALS['TSFE'];
102 }
103
104 /**
105 * @return array
106 */
107 public function getJavaScriptFiles(): array
108 {
109 return ['EXT:adminpanel/Resources/Public/JavaScript/Modules/Cache.js'];
110 }
111 }