[TASK] Speed up ReST file reference check
[Packages/TYPO3.CMS.git] / typo3 / sysext / adminpanel / Classes / Modules / EditModule.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\Adminpanel\ModuleApi\ResourceProviderInterface;
24 use TYPO3\CMS\Adminpanel\Service\EditToolbarService;
25 use TYPO3\CMS\Backend\Utility\BackendUtility;
26 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
27 use TYPO3\CMS\Core\Utility\GeneralUtility;
28 use TYPO3\CMS\Fluid\View\StandaloneView;
29 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
30
31 /**
32 * Admin Panel Edit Module
33 */
34 class EditModule extends AbstractModule implements PageSettingsProviderInterface, InitializableInterface, ResourceProviderInterface
35 {
36 /**
37 * Creates the content for the "edit" section ("module") of the Admin Panel
38 *
39 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
40 */
41 public function getPageSettings(): string
42 {
43 $editToolbarService = GeneralUtility::makeInstance(EditToolbarService::class);
44 $toolbar = $editToolbarService->createToolbar();
45 $view = GeneralUtility::makeInstance(StandaloneView::class);
46 $templateNameAndPath = 'EXT:adminpanel/Resources/Private/Templates/Modules/Settings/Edit.html';
47 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templateNameAndPath));
48 $view->setPartialRootPaths(['EXT:adminpanel/Resources/Private/Partials']);
49 $view->assignMultiple(
50 [
51 'feEdit' => ExtensionManagementUtility::isLoaded('feedit'),
52 'display' => [
53 'fieldIcons' => $this->configurationService->getConfigurationOption('edit', 'displayFieldIcons'),
54 'displayIcons' => $this->configurationService->getConfigurationOption('edit', 'displayIcons'),
55 ],
56 'toolbar' => $toolbar,
57 'script' => [
58 'pageUid' => (int)$this->getTypoScriptFrontendController()->page['uid'],
59 'pageModule' => $this->getPageModule(),
60 'backendScript' => BackendUtility::getBackendScript(),
61 't3BeSitenameMd5' => md5('Typo3Backend-' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']),
62 ],
63 ]
64 );
65 return $view->render();
66 }
67
68 /**
69 * @return TypoScriptFrontendController
70 */
71 protected function getTypoScriptFrontendController(): TypoScriptFrontendController
72 {
73 return $GLOBALS['TSFE'];
74 }
75
76 /**
77 * @return string
78 */
79 private function getPageModule(): string
80 {
81 $pageModule = trim($this->getBackendUser()->getTSConfig()['options.']['overridePageModule'] ?? '');
82 return BackendUtility::isModuleSetInTBE_MODULES($pageModule) ? $pageModule : 'web_layout';
83 }
84
85 /**
86 * @inheritdoc
87 */
88 public function getIdentifier(): string
89 {
90 return 'edit';
91 }
92
93 /**
94 * @inheritdoc
95 */
96 public function getIconIdentifier(): string
97 {
98 return 'actions-open';
99 }
100
101 /**
102 * @inheritdoc
103 */
104 public function getLabel(): string
105 {
106 $locallangFileAndPath = 'LLL:EXT:adminpanel/Resources/Private/Language/locallang_edit.xlf:module.label';
107 return $this->getLanguageService()->sL($locallangFileAndPath);
108 }
109
110 /**
111 * Initialize the edit module
112 * Includes the frontend edit initialization
113 *
114 * @param ServerRequestInterface $request
115 *
116 * @todo move into fe_edit (including the module)
117 */
118 public function initializeModule(ServerRequestInterface $request): void
119 {
120 $extFeEditLoaded = ExtensionManagementUtility::isLoaded('feedit');
121 $typoScriptFrontend = $this->getTypoScriptFrontendController();
122 $typoScriptFrontend->displayEditIcons = $this->configurationService->getConfigurationOption('edit', 'displayIcons');
123 $typoScriptFrontend->displayFieldEditIcons = $this->configurationService->getConfigurationOption('edit', 'displayFieldIcons');
124
125 if ($request->getQueryParams()['ADMCMD_editIcons'] ?? $request->getParsedBody()['ADMCMD_editIcons'] ?? false) {
126 $typoScriptFrontend->displayFieldEditIcons = '1';
127 }
128 if ($extFeEditLoaded && $typoScriptFrontend->displayEditIcons) {
129 $typoScriptFrontend->set_no_cache('Admin Panel: Display edit icons', true);
130 }
131 if ($extFeEditLoaded && $typoScriptFrontend->displayFieldEditIcons) {
132 $typoScriptFrontend->set_no_cache('Admin Panel: Display field edit icons', true);
133 }
134 }
135
136 /**
137 * @return array
138 */
139 public function getJavaScriptFiles(): array
140 {
141 return ['EXT:adminpanel/Resources/Public/JavaScript/Modules/Edit.js'];
142 }
143
144 /**
145 * Returns a string array with css files that will be rendered after the module
146 *
147 * @return array
148 */
149 public function getCssFiles(): array
150 {
151 return [];
152 }
153 }