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