08bfe6b45309e6aa51f5a593d2bc54e068898e19
[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->moduleTemplate->setForm('<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('web_func')) . '" 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 } else {
137 // If no access or if ID == zero
138 $title = $this->getLanguageService()->getLL('title');
139 $message = $this->getLanguageService()->getLL('clickAPage_content');
140 $view = GeneralUtility::makeInstance(StandaloneView::class);
141 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:func/Resources/Private/Templates/InfoBox.html'));
142 $view->assignMultiple(array(
143 'title' => $title,
144 'message' => $message,
145 'state' => InfoboxViewHelper::STATE_INFO
146 ));
147 $this->content = $view->render();
148 // Setting up the buttons and markers for docheader
149 $this->getButtons();
150 }
151 }
152
153 /**
154 * Generates the menu based on $this->MOD_MENU
155 *
156 * @throws \InvalidArgumentException
157 */
158 protected function generateMenu()
159 {
160 $menu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
161 $menu->setIdentifier('WebFuncJumpMenu');
162 foreach ($this->MOD_MENU['function'] as $controller => $title) {
163 $item = $menu
164 ->makeMenuItem()
165 ->setHref(
166 BackendUtility::getModuleUrl(
167 $this->moduleName,
168 [
169 'id' => $this->id,
170 'SET' => [
171 'function' => $controller
172 ]
173 ]
174 )
175 )
176 ->setTitle($title);
177 if ($controller === $this->MOD_SETTINGS['function']) {
178 $item->setActive(true);
179 }
180 $menu->addMenuItem($item);
181 }
182 $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
183 }
184
185 /**
186 * Print module content (from $this->content)
187 *
188 * @return void
189 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
190 */
191 public function printContent()
192 {
193 GeneralUtility::logDeprecatedFunction();
194 echo $this->content;
195 }
196
197 /**
198 * Create the panel of buttons for submitting the form or otherwise perform operations.
199 */
200 protected function getButtons()
201 {
202 $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
203 // CSH
204 $cshButton = $buttonBar->makeHelpButton()
205 ->setModuleName('_MOD_web_func')
206 ->setFieldName('');
207 $buttonBar->addButton($cshButton);
208 if ($this->id && is_array($this->pageinfo)) {
209 // View page
210 $viewButton = $buttonBar->makeLinkButton()
211 ->setOnClick(BackendUtility::viewOnClick($this->pageinfo['uid'], '', BackendUtility::BEgetRootLine($this->pageinfo['uid'])))
212 ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', true))
213 ->setIcon($this->iconFactory->getIcon('actions-document-view', Icon::SIZE_SMALL))
214 ->setHref('#');
215 $buttonBar->addButton($viewButton);
216 // Shortcut
217 $shortcutButton = $buttonBar->makeShortcutButton()
218 ->setModuleName($this->moduleName)
219 ->setGetVariables(['id', 'edit_record', 'pointer', 'new_unique_uid', 'search_field', 'search_levels', 'showLimit'])
220 ->setSetVariables(array_keys($this->MOD_MENU));
221 $buttonBar->addButton($shortcutButton);
222 }
223 }
224
225 /**
226 * Returns LanguageService
227 *
228 * @return \TYPO3\CMS\Lang\LanguageService
229 */
230 protected function getLanguageService()
231 {
232 return $GLOBALS['LANG'];
233 }
234
235 /**
236 * Returns the current BE user.
237 *
238 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
239 */
240 protected function getBackendUser()
241 {
242 return $GLOBALS['BE_USER'];
243 }
244 }