[TASK] Remove usage of setForm from PageFunctionsController
[Packages/TYPO3.CMS.git] / typo3 / sysext / func / Classes / Controller / PageFunctionsController.php
1 <?php
2 namespace TYPO3\CMS\Func\Controller;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
19 use TYPO3\CMS\Backend\Template\Components\ButtonBar;
20 use TYPO3\CMS\Backend\Template\ModuleTemplate;
21 use TYPO3\CMS\Backend\Utility\BackendUtility;
22 use TYPO3\CMS\Core\Imaging\Icon;
23 use TYPO3\CMS\Core\Imaging\IconFactory;
24 use TYPO3\CMS\Core\Utility\GeneralUtility;
25 use TYPO3\CMS\Fluid\View\StandaloneView;
26 use TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper;
27
28 /**
29 * Script Class for the Web > Functions module
30 * This class creates the framework to which other extensions can connect their sub-modules
31 */
32 class PageFunctionsController extends \TYPO3\CMS\Backend\Module\BaseScriptClass
33 {
34 /**
35 * @var array
36 * @internal
37 */
38 public $pageinfo;
39
40 /**
41 * ModuleTemplate Container
42 *
43 * @var ModuleTemplate
44 */
45 protected $moduleTemplate;
46
47 /**
48 * Document Template Object
49 *
50 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
51 */
52 public $doc;
53
54 /**
55 * The name of the module
56 *
57 * @var string
58 */
59 protected $moduleName = 'web_func';
60
61 /**
62 * @var IconFactory
63 */
64 protected $iconFactory;
65
66 /**
67 * Constructor
68 */
69 public function __construct()
70 {
71 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
72 $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
73 $this->getLanguageService()->includeLLFile('EXT:lang/locallang_mod_web_func.xlf');
74 $this->MCONF = array(
75 'name' => $this->moduleName,
76 );
77 }
78
79 /**
80 * Injects the request object for the current request or subrequest
81 * Then checks for module functions that have hooked in, and renders menu etc.
82 *
83 * @param ServerRequestInterface $request the current request
84 * @param ResponseInterface $response
85 * @return ResponseInterface the response with the content
86 */
87 public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
88 {
89 $GLOBALS['SOBE'] = $this;
90 $this->init();
91
92 // Checking for first level external objects
93 $this->checkExtObj();
94
95 // Checking second level external objects
96 $this->checkSubExtObj();
97 $this->main();
98
99 $this->moduleTemplate->setContent($this->content);
100
101 $response->getBody()->write($this->moduleTemplate->renderContent());
102 return $response;
103 }
104
105 /**
106 * Initialize module header etc and call extObjContent function
107 *
108 * @return void
109 */
110 public function main()
111 {
112 // Access check...
113 // The page will show only if there is a valid page and if this page may be viewed by the user
114 $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
115 $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($this->pageinfo);
116 $access = is_array($this->pageinfo);
117 // We keep this here, in case somebody relies on the old doc being here
118 $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
119 // Main
120 if ($this->id && $access) {
121 // JavaScript
122 $this->moduleTemplate->addJavaScriptCode(
123 'WebFuncInLineJS',
124 'if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';');
125 // Setting up the context sensitive menu:
126 $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ClickMenu');
127 $this->content .= '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('web_func')) . '" id="PageFunctionsController" method="post"><input type="hidden" name="id" value="' . htmlspecialchars($this->id) . '" />';
128 $vContent = $this->moduleTemplate->getVersionSelector($this->id, true);
129 if ($vContent) {
130 $this->content .= $this->moduleTemplate->section('', $vContent);
131 }
132 $this->extObjContent();
133 // Setting up the buttons and markers for docheader
134 $this->getButtons();
135 $this->generateMenu();
136 $this->content .= '</form>';
137 } else {
138 // If no access or if ID == zero
139 $title = $this->getLanguageService()->getLL('title');
140 $message = $this->getLanguageService()->getLL('clickAPage_content');
141 $view = GeneralUtility::makeInstance(StandaloneView::class);
142 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:func/Resources/Private/Templates/InfoBox.html'));
143 $view->assignMultiple(array(
144 'title' => $title,
145 'message' => $message,
146 'state' => InfoboxViewHelper::STATE_INFO
147 ));
148 $this->content = $view->render();
149 // Setting up the buttons and markers for docheader
150 $this->getButtons();
151 }
152 }
153
154 /**
155 * Generates the menu based on $this->MOD_MENU
156 *
157 * @throws \InvalidArgumentException
158 */
159 protected function generateMenu()
160 {
161 $menu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
162 $menu->setIdentifier('WebFuncJumpMenu');
163 foreach ($this->MOD_MENU['function'] as $controller => $title) {
164 $item = $menu
165 ->makeMenuItem()
166 ->setHref(
167 BackendUtility::getModuleUrl(
168 $this->moduleName,
169 [
170 'id' => $this->id,
171 'SET' => [
172 'function' => $controller
173 ]
174 ]
175 )
176 )
177 ->setTitle($title);
178 if ($controller === $this->MOD_SETTINGS['function']) {
179 $item->setActive(true);
180 }
181 $menu->addMenuItem($item);
182 }
183 $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
184 }
185
186 /**
187 * Print module content (from $this->content)
188 *
189 * @return void
190 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
191 */
192 public function printContent()
193 {
194 GeneralUtility::logDeprecatedFunction();
195 echo $this->content;
196 }
197
198 /**
199 * Create the panel of buttons for submitting the form or otherwise perform operations.
200 */
201 protected function getButtons()
202 {
203 $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
204 // CSH
205 $cshButton = $buttonBar->makeHelpButton()
206 ->setModuleName('_MOD_web_func')
207 ->setFieldName('');
208 $buttonBar->addButton($cshButton);
209 if ($this->id && is_array($this->pageinfo)) {
210 // View page
211 $viewButton = $buttonBar->makeLinkButton()
212 ->setOnClick(BackendUtility::viewOnClick($this->pageinfo['uid'], '', BackendUtility::BEgetRootLine($this->pageinfo['uid'])))
213 ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', true))
214 ->setIcon($this->iconFactory->getIcon('actions-document-view', Icon::SIZE_SMALL))
215 ->setHref('#');
216 $buttonBar->addButton($viewButton);
217 // Shortcut
218 $shortcutButton = $buttonBar->makeShortcutButton()
219 ->setModuleName($this->moduleName)
220 ->setGetVariables(['id', 'edit_record', 'pointer', 'new_unique_uid', 'search_field', 'search_levels', 'showLimit'])
221 ->setSetVariables(array_keys($this->MOD_MENU));
222 $buttonBar->addButton($shortcutButton);
223 }
224 }
225
226 /**
227 * Returns LanguageService
228 *
229 * @return \TYPO3\CMS\Lang\LanguageService
230 */
231 protected function getLanguageService()
232 {
233 return $GLOBALS['LANG'];
234 }
235
236 /**
237 * Returns the current BE user.
238 *
239 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
240 */
241 protected function getBackendUser()
242 {
243 return $GLOBALS['BE_USER'];
244 }
245 }