77a740bafa5dcd7108354929f7e2bcfd6ef81c49
[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 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
117 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
118 $this->view->assign('moduleName', (string)$uriBuilder->buildUriFromRoute($this->moduleName));
119 $this->view->assign('functionMenuModuleContent', $this->getExtObjContent());
120 // Setting up the buttons and markers for docheader
121 $this->getButtons();
122 $this->generateMenu();
123 $this->content .= $this->view->render();
124 } else {
125 // If no access or if ID == zero
126 $this->content = $this->moduleTemplate->header($this->languageService->getLL('title'));
127 }
128 }
129
130 /**
131 * Injects the request object for the current request or subrequest
132 * Then checks for module functions that have hooked in, and renders menu etc.
133 *
134 * @param ServerRequestInterface $request the current request
135 * @param ResponseInterface $response
136 * @return ResponseInterface the response with the content
137 */
138 public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
139 {
140 $GLOBALS['SOBE'] = $this;
141 $this->init();
142
143 // Checking for first level external objects
144 $this->checkExtObj();
145
146 // Checking second level external objects
147 $this->checkSubExtObj();
148 $this->main();
149
150 $this->moduleTemplate->setContent($this->content);
151 $response->getBody()->write($this->moduleTemplate->renderContent());
152 return $response;
153 }
154
155 /**
156 * Create the panel of buttons for submitting the form or otherwise perform operations.
157 */
158 protected function getButtons()
159 {
160 $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
161 // View page
162 $viewButton = $buttonBar->makeLinkButton()
163 ->setHref('#')
164 ->setOnClick(BackendUtility::viewOnClick(
165 $this->pageinfo['uid'],
166 '',
167 BackendUtility::BEgetRootLine($this->pageinfo['uid'])
168 ))
169 ->setTitle($this->languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.showPage'))
170 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-page', Icon::SIZE_SMALL));
171 $buttonBar->addButton($viewButton, ButtonBar::BUTTON_POSITION_LEFT, 1);
172 // Shortcut
173 $shortCutButton = $buttonBar->makeShortcutButton()
174 ->setModuleName($this->moduleName)
175 ->setDisplayName($this->MOD_MENU['function'][$this->MOD_SETTINGS['function']])
176 ->setGetVariables([
177 'route',
178 'id',
179 'edit_record',
180 'pointer',
181 'new_unique_uid',
182 'search_field',
183 'search_levels',
184 'showLimit'
185 ])
186 ->setSetVariables(array_keys($this->MOD_MENU));
187 $buttonBar->addButton($shortCutButton, ButtonBar::BUTTON_POSITION_RIGHT);
188
189 // CSH
190 $cshButton = $buttonBar->makeHelpButton()
191 ->setModuleName('xMOD_csh_corebe')
192 ->setFieldName('pagetree_overview');
193 $buttonBar->addButton($cshButton);
194 }
195
196 /**
197 * Generate the ModuleMenu
198 */
199 protected function generateMenu()
200 {
201 $menu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
202 $menu->setIdentifier('WebInfoJumpMenu');
203 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
204 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
205 foreach ($this->MOD_MENU['function'] as $controller => $title) {
206 $item = $menu
207 ->makeMenuItem()
208 ->setHref(
209 (string)$uriBuilder->buildUriFromRoute(
210 $this->moduleName,
211 [
212 'id' => $this->id,
213 'SET' => [
214 'function' => $controller
215 ]
216 ]
217 )
218 )
219 ->setTitle($title);
220 if ($controller === $this->MOD_SETTINGS['function']) {
221 $item->setActive(true);
222 }
223 $menu->addMenuItem($item);
224 }
225 $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
226 }
227
228 /**
229 * Returns the ModuleTemplate container
230 * This is used by PageLayoutView.php
231 *
232 * @return ModuleTemplate
233 */
234 public function getModuleTemplate()
235 {
236 return $this->moduleTemplate;
237 }
238
239 /**
240 * returns a new standalone view, shorthand function
241 *
242 * @return StandaloneView
243 */
244 protected function getFluidTemplateObject()
245 {
246 /** @var StandaloneView $view */
247 $view = GeneralUtility::makeInstance(StandaloneView::class);
248 $view->setLayoutRootPaths([GeneralUtility::getFileAbsFileName('EXT:info/Resources/Private/Layouts')]);
249 $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:info/Resources/Private/Partials')]);
250 $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:info/Resources/Private/Templates')]);
251
252 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:info/Resources/Private/Templates/Main.html'));
253
254 $view->getRequest()->setControllerExtensionName('info');
255 return $view;
256 }
257 }