e89111a31504ecb36a9eab8d898e90c3e69aed1c
[Packages/TYPO3.CMS.git] / typo3 / sysext / info / Classes / Controller / InfoModuleController.php
1 <?php
2 namespace TYPO3\CMS\Info\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\Module\BaseScriptClass;
20 use TYPO3\CMS\Backend\Template\Components\ButtonBar;
21 use TYPO3\CMS\Backend\Template\ModuleTemplate;
22 use TYPO3\CMS\Backend\Utility\BackendUtility;
23 use TYPO3\CMS\Core\Imaging\Icon;
24 use TYPO3\CMS\Core\Utility\GeneralUtility;
25 use TYPO3\CMS\Fluid\View\StandaloneView;
26
27 /**
28 * Script Class for the Web > Info module
29 * This class creates the framework to which other extensions can connect their sub-modules
30 */
31 class InfoModuleController extends BaseScriptClass
32 {
33 /**
34 * @var array
35 */
36 public $pageinfo;
37
38 /**
39 * @var \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
40 */
41 protected $backendUser;
42
43 /**
44 * @var \TYPO3\CMS\Core\Localization\LanguageService
45 */
46 protected $languageService;
47
48 /**
49 * The name of the module
50 *
51 * @var string
52 */
53 protected $moduleName = 'web_info';
54
55 /**
56 * ModuleTemplate Container
57 *
58 * @var ModuleTemplate
59 */
60 protected $moduleTemplate;
61
62 /**
63 * @var StandaloneView
64 */
65 protected $view;
66
67 /**
68 * Constructor
69 */
70 public function __construct()
71 {
72 $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
73 $this->languageService = $GLOBALS['LANG'];
74 $this->languageService->includeLLFile('EXT:info/Resources/Private/Language/locallang_mod_web_info.xlf');
75
76 $this->backendUser = $GLOBALS['BE_USER'];
77
78 $this->MCONF = [
79 'name' => $this->moduleName,
80 ];
81 }
82
83 /**
84 * Initialize module header etc and call extObjContent function
85 */
86 public function main()
87 {
88 // We leave this here because of dependencies to submodules
89 $this->doc = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
90
91 // The page will show only if there is a valid page and if this page
92 // may be viewed by the user
93 $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
94 if ($this->pageinfo) {
95 $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($this->pageinfo);
96 }
97 $access = is_array($this->pageinfo);
98 if ($this->id && $access || $this->backendUser->isAdmin() && !$this->id) {
99 if ($this->backendUser->isAdmin() && !$this->id) {
100 $this->pageinfo = ['title' => '[root-level]', 'uid' => 0, 'pid' => 0];
101 }
102 // JavaScript
103 $this->moduleTemplate->addJavaScriptCode(
104 'WebFuncInLineJS',
105 'if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
106 function jumpToUrl(URL) {
107 window.location.href = URL;
108 return false;
109 }
110 '
111 );
112 // Setting up the context sensitive menu:
113 $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
114
115 $this->view = $this->getFluidTemplateObject();
116 $this->view->assign('moduleName', BackendUtility::getModuleUrl($this->moduleName));
117 $this->view->assign('functionMenuModuleContent', $this->getExtObjContent());
118 // Setting up the buttons and markers for docheader
119 $this->getButtons();
120 $this->generateMenu();
121 $this->content .= $this->view->render();
122 } else {
123 // If no access or if ID == zero
124 $this->content = $this->moduleTemplate->header($this->languageService->getLL('title'));
125 }
126 }
127
128 /**
129 * Injects the request object for the current request or subrequest
130 * Then checks for module functions that have hooked in, and renders menu etc.
131 *
132 * @param ServerRequestInterface $request the current request
133 * @param ResponseInterface $response
134 * @return ResponseInterface the response with the content
135 */
136 public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
137 {
138 $GLOBALS['SOBE'] = $this;
139 $this->init();
140
141 // Checking for first level external objects
142 $this->checkExtObj();
143
144 // Checking second level external objects
145 $this->checkSubExtObj();
146 $this->main();
147
148 $this->moduleTemplate->setContent($this->content);
149 $response->getBody()->write($this->moduleTemplate->renderContent());
150 return $response;
151 }
152
153 /**
154 * Create the panel of buttons for submitting the form or otherwise perform operations.
155 */
156 protected function getButtons()
157 {
158 $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
159 // View page
160 $viewButton = $buttonBar->makeLinkButton()
161 ->setHref('#')
162 ->setOnClick(BackendUtility::viewOnClick(
163 $this->pageinfo['uid'],
164 '',
165 BackendUtility::BEgetRootLine($this->pageinfo['uid'])
166 ))
167 ->setTitle($this->languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.showPage'))
168 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-page', Icon::SIZE_SMALL));
169 $buttonBar->addButton($viewButton, ButtonBar::BUTTON_POSITION_LEFT, 1);
170 // Shortcut
171 $shortCutButton = $buttonBar->makeShortcutButton()
172 ->setModuleName($this->moduleName)
173 ->setDisplayName($this->MOD_MENU['function'][$this->MOD_SETTINGS['function']])
174 ->setGetVariables([
175 'route',
176 'id',
177 'edit_record',
178 'pointer',
179 'new_unique_uid',
180 'search_field',
181 'search_levels',
182 'showLimit'
183 ])
184 ->setSetVariables(array_keys($this->MOD_MENU));
185 $buttonBar->addButton($shortCutButton, ButtonBar::BUTTON_POSITION_RIGHT);
186
187 // CSH
188 $cshButton = $buttonBar->makeHelpButton()
189 ->setModuleName('xMOD_csh_corebe')
190 ->setFieldName('pagetree_overview');
191 $buttonBar->addButton($cshButton);
192 }
193
194 /**
195 * Generate the ModuleMenu
196 */
197 protected function generateMenu()
198 {
199 $menu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
200 $menu->setIdentifier('WebInfoJumpMenu');
201 foreach ($this->MOD_MENU['function'] as $controller => $title) {
202 $item = $menu
203 ->makeMenuItem()
204 ->setHref(
205 BackendUtility::getModuleUrl(
206 $this->moduleName,
207 [
208 'id' => $this->id,
209 'SET' => [
210 'function' => $controller
211 ]
212 ]
213 )
214 )
215 ->setTitle($title);
216 if ($controller === $this->MOD_SETTINGS['function']) {
217 $item->setActive(true);
218 }
219 $menu->addMenuItem($item);
220 }
221 $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
222 }
223
224 /**
225 * Returns the ModuleTemplate container
226 * This is used by PageLayoutView.php
227 *
228 * @return ModuleTemplate
229 */
230 public function getModuleTemplate()
231 {
232 return $this->moduleTemplate;
233 }
234
235 /**
236 * returns a new standalone view, shorthand function
237 *
238 * @return StandaloneView
239 */
240 protected function getFluidTemplateObject()
241 {
242 /** @var StandaloneView $view */
243 $view = GeneralUtility::makeInstance(StandaloneView::class);
244 $view->setLayoutRootPaths([GeneralUtility::getFileAbsFileName('EXT:info/Resources/Private/Layouts')]);
245 $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:info/Resources/Private/Partials')]);
246 $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:info/Resources/Private/Templates')]);
247
248 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:info/Resources/Private/Templates/Main.html'));
249
250 $view->getRequest()->setControllerExtensionName('info');
251 return $view;
252 }
253 }