[TASK] Decouple adminPanel from frontend
[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 TYPO3\CMS\Adminpanel\Service\EditToolbarService;
20 use TYPO3\CMS\Backend\Utility\BackendUtility;
21 use TYPO3\CMS\Core\Http\ServerRequest;
22 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
23 use TYPO3\CMS\Core\Utility\GeneralUtility;
24 use TYPO3\CMS\Fluid\View\StandaloneView;
25 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
26
27 /**
28 * Admin Panel Edit Module
29 */
30 class EditModule extends AbstractModule
31 {
32 /**
33 * Creates the content for the "edit" section ("module") of the Admin Panel
34 *
35 * @return string HTML content for the section. Consists of a string with table-rows with four columns.
36 */
37 public function getContent(): string
38 {
39 $view = GeneralUtility::makeInstance(StandaloneView::class);
40 $templateNameAndPath = $this->extResources . '/Templates/Modules/Edit.html';
41 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templateNameAndPath));
42 $view->setPartialRootPaths([$this->extResources . '/Partials']);
43
44 $editToolbarService = GeneralUtility::makeInstance(EditToolbarService::class);
45 $view->assignMultiple([
46 'feEdit' => ExtensionManagementUtility::isLoaded('feedit'),
47 'display' => [
48 'edit' => $this->getBackendUser()->uc['TSFE_adminConfig']['display_edit'],
49 'fieldIcons' => $this->getConfigurationOption('displayFieldIcons'),
50 'displayIcons' => $this->getConfigurationOption('displayIcons'),
51 ],
52 'toolbar' => $editToolbarService->createToolbar(),
53 'script' => [
54 'pageUid' => (int)$this->getTypoScriptFrontendController()->page['uid'],
55 'pageModule' => $this->getPageModule(),
56 'backendScript' => BackendUtility::getBackendScript(),
57 't3BeSitenameMd5' => \md5('Typo3Backend-' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']),
58 ],
59 ]);
60
61 return $view->render();
62 }
63
64 /**
65 * @return TypoScriptFrontendController
66 */
67 protected function getTypoScriptFrontendController(): TypoScriptFrontendController
68 {
69 return $GLOBALS['TSFE'];
70 }
71
72 /**
73 * @return string
74 */
75 private function getPageModule(): string
76 {
77 $newPageModule = \trim(
78 (string)$this->getBackendUser()
79 ->getTSConfigVal('options.overridePageModule')
80 );
81 return BackendUtility::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
82 }
83
84 /**
85 * @inheritdoc
86 */
87 public function getIdentifier(): string
88 {
89 return 'edit';
90 }
91
92 /**
93 * @inheritdoc
94 */
95 public function getLabel(): string
96 {
97 return $this->extGetLL('edit');
98 }
99
100 /**
101 * Initialize the edit module
102 * Includes the frontend edit initialization
103 *
104 * @param ServerRequest $request
105 *
106 * @todo move into fe_edit (including the module)
107 */
108 public function initializeModule(ServerRequest $request): void
109 {
110 $extFeEditLoaded = ExtensionManagementUtility::isLoaded('feedit');
111 $typoScriptFrontend = $this->getTypoScriptFrontendController();
112 $typoScriptFrontend->displayEditIcons = $this->getConfigurationOption('displayIcons');
113 $typoScriptFrontend->displayFieldEditIcons = $this->getConfigurationOption('displayFieldIcons');
114
115 if (GeneralUtility::_GP('ADMCMD_editIcons')) {
116 $typoScriptFrontend->displayFieldEditIcons = '1';
117 }
118 if ($extFeEditLoaded && $typoScriptFrontend->displayEditIcons) {
119 $typoScriptFrontend->set_no_cache('Admin Panel: Display edit icons', true);
120 }
121 if ($extFeEditLoaded && $typoScriptFrontend->displayFieldEditIcons) {
122 $typoScriptFrontend->set_no_cache('Admin Panel: Display field edit icons', true);
123 }
124 }
125
126 /**
127 * @inheritdoc
128 */
129 public function showFormSubmitButton(): bool
130 {
131 return true;
132 }
133
134 /**
135 * @return array
136 */
137 public function getJavaScriptFiles(): array
138 {
139 return ['EXT:adminpanel/Resources/Public/JavaScript/Modules/Edit/OpenBackendHandler.js'];
140 }
141 }