‪TYPO3CMS  ‪main
CacheModule.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
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 
19 
20 use Psr\Http\Message\ServerRequestInterface;
30 
32 {
33  public function ‪getIconIdentifier(): string
34  {
35  return 'apps-toolbar-menu-cache';
36  }
37 
38  public function ‪getPageSettings(): string
39  {
40  $view = GeneralUtility::makeInstance(StandaloneView::class);
41  $templateNameAndPath = 'EXT:adminpanel/Resources/Private/Templates/Modules/Settings/Cache.html';
42  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templateNameAndPath));
43  $view->setPartialRootPaths(['EXT:adminpanel/Resources/Private/Partials']);
44 
45  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
46  $feCacheClear = $this->‪getBackendUser()->isAdmin()
47  || !empty($this->‪getBackendUser()->getTSConfig()['options.']['clearCache.']['pages']);
48 
49  $pageId = 0;
50  $pageArguments = ‪$GLOBALS['TYPO3_REQUEST']->getAttribute('routing');
51  if ($pageArguments instanceof ‪PageArguments) {
52  $pageId = $pageArguments->getPageId();
53  }
54 
55  $view->assignMultiple(
56  [
57  'isEnabled' => $this->‪getBackendUser()->uc['AdminPanel']['display_cache'] ?? false,
58  'noCache' => $this->‪getBackendUser()->uc['AdminPanel']['cache_noCache'] ?? false,
59  'currentId' => $pageId,
60  'clearPageCacheUrl' => $feCacheClear ? (string)$uriBuilder->buildUriFromRoute('tce_db', ['cacheCmd' => 'pages']) : '',
61  'clearCurrentPageCacheUrl' => (string)$uriBuilder->buildUriFromRoute(
62  'tce_db',
63  [
64  'cacheCmd' => $pageId,
65  ]
66  ),
67  'languageKey' => $this->getBackendUser()->user['lang'] ?? null,
68  ]
69  );
70 
71  return $view->render();
72  }
73 
74  public function ‪getIdentifier(): string
75  {
76  return 'cache';
77  }
78 
79  public function ‪getLabel(): string
80  {
81  $locallangFileAndPath = 'LLL:EXT:adminpanel/Resources/Private/Language/locallang_cache.xlf:module.label';
82  return $this->‪getLanguageService()->sL($locallangFileAndPath);
83  }
84 
85  public function ‪enrich(ServerRequestInterface $request): ServerRequestInterface
86  {
87  if ($this->configurationService->getConfigurationOption('cache', 'noCache')) {
88  $cacheInstruction = $request->getAttribute('frontend.cache.instruction', new ‪CacheInstruction());
89  $cacheInstruction->disableCache('EXT:adminpanel: "No caching" disables cache.');
90  $request = $request->withAttribute('frontend.cache.instruction', $cacheInstruction);
91  }
92  return $request;
93  }
94 
95  public function ‪getJavaScriptFiles(): array
96  {
97  return ['EXT:adminpanel/Resources/Public/JavaScript/modules/cache.js'];
98  }
99 
105  public function ‪getCssFiles(): array
106  {
107  return [];
108  }
109 }
‪TYPO3\CMS\Core\Routing\PageArguments
Definition: PageArguments.php:26
‪TYPO3\CMS\Adminpanel\ModuleApi\AbstractModule
Definition: AbstractModule.php:29
‪TYPO3\CMS\Adminpanel\Modules\CacheModule
Definition: CacheModule.php:32
‪TYPO3\CMS\Adminpanel\Modules\CacheModule\getIconIdentifier
‪getIconIdentifier()
Definition: CacheModule.php:33
‪TYPO3\CMS\Adminpanel\ModuleApi\AbstractModule\getBackendUser
‪getBackendUser()
Definition: AbstractModule.php:90
‪TYPO3\CMS\Adminpanel\ModuleApi\AbstractModule\getLanguageService
‪getLanguageService()
Definition: AbstractModule.php:95
‪TYPO3\CMS\Adminpanel\Modules\CacheModule\getLabel
‪getLabel()
Definition: CacheModule.php:79
‪TYPO3\CMS\Adminpanel\ModuleApi\ResourceProviderInterface
Definition: ResourceProviderInterface.php:27
‪TYPO3\CMS\Adminpanel\Modules\CacheModule\enrich
‪enrich(ServerRequestInterface $request)
Definition: CacheModule.php:85
‪TYPO3\CMS\Adminpanel\Modules\CacheModule\getCssFiles
‪getCssFiles()
Definition: CacheModule.php:105
‪TYPO3\CMS\Adminpanel\Modules\CacheModule\getPageSettings
‪getPageSettings()
Definition: CacheModule.php:38
‪TYPO3\CMS\Adminpanel\Modules
Definition: CacheModule.php:18
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:44
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:30
‪TYPO3\CMS\Adminpanel\ModuleApi\PageSettingsProviderInterface
Definition: PageSettingsProviderInterface.php:32
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Frontend\Cache\CacheInstruction
Definition: CacheInstruction.php:29
‪TYPO3\CMS\Adminpanel\Modules\CacheModule\getIdentifier
‪getIdentifier()
Definition: CacheModule.php:74
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Adminpanel\Modules\CacheModule\getJavaScriptFiles
‪getJavaScriptFiles()
Definition: CacheModule.php:95
‪TYPO3\CMS\Adminpanel\ModuleApi\RequestEnricherInterface
Definition: RequestEnricherInterface.php:37