[CLEANUP] Use Permission constants consistently
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / BackendController.php
1 <?php
2 namespace TYPO3\CMS\Backend\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\Domain\Repository\Module\BackendModuleRepository;
20 use TYPO3\CMS\Backend\Module\ModuleLoader;
21 use TYPO3\CMS\Backend\Routing\UriBuilder;
22 use TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface;
23 use TYPO3\CMS\Backend\Utility\BackendUtility;
24 use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
25 use TYPO3\CMS\Core\Database\ConnectionPool;
26 use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
27 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
28 use TYPO3\CMS\Core\Http\JsonResponse;
29 use TYPO3\CMS\Core\Imaging\IconFactory;
30 use TYPO3\CMS\Core\Page\PageRenderer;
31 use TYPO3\CMS\Core\Type\Bitmask\Permission;
32 use TYPO3\CMS\Core\Type\File\ImageInfo;
33 use TYPO3\CMS\Core\Utility\GeneralUtility;
34 use TYPO3\CMS\Core\Utility\MathUtility;
35 use TYPO3\CMS\Core\Utility\PathUtility;
36 use TYPO3\CMS\Fluid\View\StandaloneView;
37
38 /**
39 * Class for rendering the TYPO3 backend
40 */
41 class BackendController
42 {
43 /**
44 * @var string
45 */
46 protected $content = '';
47
48 /**
49 * @var string
50 */
51 protected $css = '';
52
53 /**
54 * @var array
55 */
56 protected $cssFiles = [];
57
58 /**
59 * @var string
60 */
61 protected $js = '';
62
63 /**
64 * @var array
65 */
66 protected $jsFiles = [];
67
68 /**
69 * @var array
70 */
71 protected $toolbarItems = [];
72
73 /**
74 * @var bool
75 */
76 protected $debug;
77
78 /**
79 * @var string
80 */
81 protected $templatePath = 'EXT:backend/Resources/Private/Templates/';
82
83 /**
84 * @var string
85 */
86 protected $partialPath = 'EXT:backend/Resources/Private/Partials/';
87
88 /**
89 * @var \TYPO3\CMS\Backend\Domain\Repository\Module\BackendModuleRepository
90 */
91 protected $backendModuleRepository;
92
93 /**
94 * @var \TYPO3\CMS\Backend\Module\ModuleLoader Object for loading backend modules
95 */
96 protected $moduleLoader;
97
98 /**
99 * @var PageRenderer
100 */
101 protected $pageRenderer;
102
103 /**
104 * @var IconFactory
105 */
106 protected $iconFactory;
107
108 /**
109 * Constructor
110 */
111 public function __construct()
112 {
113 $this->getLanguageService()->includeLLFile('EXT:lang/Resources/Private/Language/locallang_misc.xlf');
114
115 $this->backendModuleRepository = GeneralUtility::makeInstance(BackendModuleRepository::class);
116 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
117 $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
118 // Set debug flag for BE development only
119 $this->debug = (int)$GLOBALS['TYPO3_CONF_VARS']['BE']['debug'] === 1;
120 // Initializes the backend modules structure for use later.
121 $this->moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class);
122 $this->moduleLoader->load($GLOBALS['TBE_MODULES']);
123 $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
124 // included for the module menu JavaScript, please note that this is subject to change
125 $this->pageRenderer->loadJquery();
126 // Add default BE javascript
127 $this->jsFiles = [
128 'md5' => 'EXT:backend/Resources/Public/JavaScript/md5.js',
129 'evalfield' => 'EXT:backend/Resources/Public/JavaScript/jsfunc.evalfield.js',
130 'backend' => 'EXT:backend/Resources/Public/JavaScript/backend.js',
131 ];
132 $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LoginRefresh', 'function(LoginRefresh) {
133 LoginRefresh.setIntervalTime(' . MathUtility::forceIntegerInRange((int)$GLOBALS['TYPO3_CONF_VARS']['BE']['sessionTimeout'] - 60, 60) . ');
134 LoginRefresh.setLoginFramesetUrl(' . GeneralUtility::quoteJSvalue((string)$uriBuilder->buildUriFromRoute('login_frameset')) . ');
135 LoginRefresh.setLogoutUrl(' . GeneralUtility::quoteJSvalue((string)$uriBuilder->buildUriFromRoute('logout')) . ');
136 LoginRefresh.initialize();
137 }');
138
139 // load module menu
140 $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ModuleMenu');
141
142 // load Toolbar class
143 $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Toolbar');
144
145 // load Utility class
146 $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Utility');
147
148 // load Notification functionality
149 $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Notification');
150
151 // load Modals
152 $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
153
154 // load ContextMenu
155 $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
156
157 // load the storage API and fill the UC into the PersistentStorage, so no additional AJAX call is needed
158 $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Storage');
159 $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Storage/Persistent', 'function(PersistentStorage) {
160 PersistentStorage.load(' . json_encode($this->getBackendUser()->uc) . ');
161 }');
162
163 // load debug console
164 $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/DebugConsole');
165
166 $this->pageRenderer->addInlineLanguageLabelFile('EXT:lang/Resources/Private/Language/locallang_core.xlf');
167 $this->pageRenderer->addInlineLanguageLabelFile('EXT:lang/Resources/Private/Language/locallang_misc.xlf');
168 $this->pageRenderer->addInlineLanguageLabelFile('EXT:backend/Resources/Private/Language/locallang_layout.xlf');
169
170 $this->pageRenderer->addInlineLanguageLabelFile('EXT:core/Resources/Private/Language/debugger.xlf');
171 $this->pageRenderer->addInlineLanguageLabelFile('EXT:core/Resources/Private/Language/wizard.xlf');
172
173 $this->pageRenderer->addInlineSetting('ShowItem', 'moduleUrl', (string)$uriBuilder->buildUriFromRoute('show_item'));
174 $this->pageRenderer->addInlineSetting('RecordHistory', 'moduleUrl', (string)$uriBuilder->buildUriFromRoute('record_history'));
175 $this->pageRenderer->addInlineSetting('NewRecord', 'moduleUrl', (string)$uriBuilder->buildUriFromRoute('db_new'));
176 $this->pageRenderer->addInlineSetting('FormEngine', 'moduleUrl', (string)$uriBuilder->buildUriFromRoute('record_edit'));
177 $this->pageRenderer->addInlineSetting('RecordCommit', 'moduleUrl', (string)$uriBuilder->buildUriFromRoute('tce_db'));
178 $this->pageRenderer->addInlineSetting('WebLayout', 'moduleUrl', (string)$uriBuilder->buildUriFromRoute('web_layout'));
179
180 $this->css = '';
181
182 $this->initializeToolbarItems();
183 $this->executeHook('constructPostProcess');
184 }
185
186 /**
187 * Initialize toolbar item objects
188 *
189 * @throws \RuntimeException
190 */
191 protected function initializeToolbarItems()
192 {
193 $toolbarItemInstances = [];
194 foreach ($GLOBALS['TYPO3_CONF_VARS']['BE']['toolbarItems'] ?? [] as $className) {
195 $toolbarItemInstance = GeneralUtility::makeInstance($className);
196 if (!$toolbarItemInstance instanceof ToolbarItemInterface) {
197 throw new \RuntimeException(
198 'class ' . $className . ' is registered as toolbar item but does not implement'
199 . ToolbarItemInterface::class,
200 1415958218
201 );
202 }
203 $index = (int)$toolbarItemInstance->getIndex();
204 if ($index < 0 || $index > 100) {
205 throw new \RuntimeException(
206 'getIndex() must return an integer between 0 and 100',
207 1415968498
208 );
209 }
210 // Find next free position in array
211 while (array_key_exists($index, $toolbarItemInstances)) {
212 $index++;
213 }
214 $toolbarItemInstances[$index] = $toolbarItemInstance;
215 }
216 ksort($toolbarItemInstances);
217 $this->toolbarItems = $toolbarItemInstances;
218 }
219
220 /**
221 * Injects the request object for the current request or subrequest
222 * As this controller goes only through the render() method, it is rather simple for now
223 *
224 * @param ServerRequestInterface $request the current request
225 * @param ResponseInterface $response
226 * @return ResponseInterface the response with the content
227 */
228 public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
229 {
230 $this->render();
231 $response->getBody()->write($this->content);
232 return $response;
233 }
234
235 /**
236 * Main function generating the BE scaffolding
237 */
238 public function render()
239 {
240 $this->executeHook('renderPreProcess');
241
242 // Prepare the scaffolding, at this point extension may still add javascript and css
243 $view = $this->getFluidTemplateObject($this->templatePath . 'Backend/Main.html');
244
245 $view->assign('moduleMenu', $this->generateModuleMenu());
246 $view->assign('topbar', $this->renderTopbar());
247
248 /******************************************************
249 * Now put the complete backend document together
250 ******************************************************/
251 foreach ($this->cssFiles as $cssFileName => $cssFile) {
252 $this->pageRenderer->addCssFile($cssFile);
253 // Load additional css files to overwrite existing core styles
254 if (!empty($GLOBALS['TBE_STYLES']['stylesheets'][$cssFileName])) {
255 $this->pageRenderer->addCssFile($GLOBALS['TBE_STYLES']['stylesheets'][$cssFileName]);
256 }
257 }
258 if (!empty($this->css)) {
259 $this->pageRenderer->addCssInlineBlock('BackendInlineCSS', $this->css);
260 }
261 foreach ($this->jsFiles as $jsFile) {
262 $this->pageRenderer->addJsFile($jsFile);
263 }
264 $this->generateJavascript();
265 $this->pageRenderer->addJsInlineCode('BackendInlineJavascript', $this->js, false);
266
267 // Set document title:
268 $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] ? $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] . ' [TYPO3 CMS ' . TYPO3_version . ']' : 'TYPO3 CMS ' . TYPO3_version;
269 // Renders the module page
270 $this->content = $this->getDocumentTemplate()->render($title, $view->render());
271 $hookConfiguration = ['content' => &$this->content];
272 $this->executeHook('renderPostProcess', $hookConfiguration);
273 }
274
275 /**
276 * Renders the topbar, containing the backend logo, sitename etc.
277 *
278 * @return string
279 */
280 protected function renderTopbar()
281 {
282 $view = $this->getFluidTemplateObject($this->partialPath . 'Backend/Topbar.html');
283
284 // Extension Configuration to find the TYPO3 logo in the left corner
285 $extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('backend');
286 $logoPath = '';
287 if (!empty($extConf['backendLogo'])) {
288 $customBackendLogo = GeneralUtility::getFileAbsFileName($extConf['backendLogo']);
289 if (!empty($customBackendLogo)) {
290 $logoPath = $customBackendLogo;
291 }
292 }
293 // if no custom logo was set or the path is invalid, use the original one
294 if (empty($logoPath)) {
295 $logoPath = GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Public/Images/typo3_logo_orange.svg');
296 $logoWidth = 22;
297 $logoHeight = 22;
298 } else {
299 // set width/height for custom logo
300 $imageInfo = GeneralUtility::makeInstance(ImageInfo::class, $logoPath);
301 $logoWidth = $imageInfo->getWidth() ?? '22';
302 $logoHeight = $imageInfo->getHeight() ?? '22';
303
304 // High-resolution?
305 if (strpos($logoPath, '@2x.') !== false) {
306 $logoWidth /= 2;
307 $logoHeight /= 2;
308 }
309 }
310
311 $view->assign('logoUrl', PathUtility::getAbsoluteWebPath($logoPath));
312 $view->assign('logoWidth', $logoWidth);
313 $view->assign('logoHeight', $logoHeight);
314 $view->assign('applicationVersion', TYPO3_version);
315 $view->assign('siteName', $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
316 $view->assign('toolbar', $this->renderToolbar());
317
318 return $view->render();
319 }
320
321 /**
322 * Renders the items in the top toolbar
323 *
324 * @return string top toolbar elements as HTML
325 */
326 protected function renderToolbar()
327 {
328 $toolbar = [];
329 foreach ($this->toolbarItems as $toolbarItem) {
330 /** @var \TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface $toolbarItem */
331 if ($toolbarItem->checkAccess()) {
332 $hasDropDown = (bool)$toolbarItem->hasDropDown();
333 $additionalAttributes = (array)$toolbarItem->getAdditionalAttributes();
334
335 $liAttributes = [];
336
337 // Merge class: Add dropdown class if hasDropDown, add classes from additional attributes
338 $classes = [];
339 $classes[] = 'toolbar-item';
340 $classes[] = 't3js-toolbar-item';
341 if (isset($additionalAttributes['class'])) {
342 $classes[] = $additionalAttributes['class'];
343 unset($additionalAttributes['class']);
344 }
345 $liAttributes[] = 'class="' . implode(' ', $classes) . '"';
346
347 // Add further attributes
348 foreach ($additionalAttributes as $name => $value) {
349 $liAttributes[] = $name . '="' . $value . '"';
350 }
351
352 // Create a unique id from class name
353 $className = get_class($toolbarItem);
354 $className = GeneralUtility::underscoredToLowerCamelCase($className);
355 $className = GeneralUtility::camelCaseToLowerCaseUnderscored($className);
356 $className = str_replace(['_', '\\'], '-', $className);
357 $liAttributes[] = 'id="' . $className . '"';
358
359 $toolbar[] = '<li ' . implode(' ', $liAttributes) . '>';
360
361 if ($hasDropDown) {
362 $toolbar[] = '<a href="#" class="toolbar-item-link dropdown-toggle" data-toggle="dropdown">';
363 $toolbar[] = $toolbarItem->getItem();
364 $toolbar[] = '</a>';
365 $toolbar[] = '<div class="dropdown-menu" role="menu">';
366 $toolbar[] = $toolbarItem->getDropDown();
367 $toolbar[] = '</div>';
368 } else {
369 $toolbar[] = $toolbarItem->getItem();
370 }
371 $toolbar[] = '</li>';
372 }
373 }
374 return implode(LF, $toolbar);
375 }
376
377 /**
378 * Generates the JavaScript code for the backend.
379 */
380 protected function generateJavascript()
381 {
382 $beUser = $this->getBackendUser();
383 // Needed for FormEngine manipulation (date picker)
384 $dateFormat = ($GLOBALS['TYPO3_CONF_VARS']['SYS']['USdateFormat'] ? ['MM-DD-YYYY', 'HH:mm MM-DD-YYYY'] : ['DD-MM-YYYY', 'HH:mm DD-MM-YYYY']);
385 $this->pageRenderer->addInlineSetting('DateTimePicker', 'DateFormat', $dateFormat);
386
387 // If another page module was specified, replace the default Page module with the new one
388 $newPageModule = trim($beUser->getTSConfigVal('options.overridePageModule'));
389 $pageModule = BackendUtility::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
390 if (!$beUser->check('modules', $pageModule)) {
391 $pageModule = '';
392 }
393 $t3Configuration = [
394 'username' => htmlspecialchars($beUser->user['username']),
395 'pageModule' => $pageModule,
396 'inWorkspace' => $beUser->workspace !== 0,
397 'showRefreshLoginPopup' => isset($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) ? (int)$GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup'] : false
398 ];
399 $this->js .= '
400 TYPO3.configuration = ' . json_encode($t3Configuration) . ';
401 /**
402 * Frameset Module object
403 *
404 * Used in main modules with a frameset for submodules to keep the ID between modules
405 * Typically that is set by something like this in a Web>* sub module:
406 * if (top.fsMod) top.fsMod.recentIds["web"] = "\'.(int)$this->id.\'";
407 * if (top.fsMod) top.fsMod.recentIds["file"] = "...(file reference/string)...";
408 */
409 var fsMod = {
410 recentIds: [], // used by frameset modules to track the most recent used id for list frame.
411 navFrameHighlightedID: [], // used by navigation frames to track which row id was highlighted last time
412 currentBank: "0"
413 };
414
415 top.goToModule = function(modName, cMR_flag, addGetVars) {
416 TYPO3.ModuleMenu.App.showModule(modName, addGetVars);
417 }
418 ' . $this->setStartupModule();
419 // Check editing of page:
420 $this->handlePageEditing();
421 }
422
423 /**
424 * Checking if the "&edit" variable was sent so we can open it for editing the page.
425 */
426 protected function handlePageEditing()
427 {
428 $beUser = $this->getBackendUser();
429 // EDIT page:
430 $editId = preg_replace('/[^[:alnum:]_]/', '', GeneralUtility::_GET('edit'));
431 if ($editId) {
432 // Looking up the page to edit, checking permissions:
433 $where = ' AND (' . $beUser->getPagePermsClause(Permission::PAGE_EDIT) . ' OR ' . $beUser->getPagePermsClause(Permission::CONTENT_EDIT) . ')';
434 if (MathUtility::canBeInterpretedAsInteger($editId)) {
435 $editRecord = BackendUtility::getRecordWSOL('pages', $editId, '*', $where);
436 } else {
437 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
438 $queryBuilder->getRestrictions()
439 ->removeAll()
440 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
441 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
442
443 $editRecord = $queryBuilder->select('*')
444 ->from('pages')
445 ->where(
446 $queryBuilder->expr()->eq(
447 'alias',
448 $queryBuilder->createNamedParameter($editId, \PDO::PARAM_STR)
449 ),
450 $queryBuilder->expr()->orX(
451 $beUser->getPagePermsClause(Permission::PAGE_EDIT),
452 $beUser->getPagePermsClause(Permission::CONTENT_EDIT)
453 )
454 )
455 ->setMaxResults(1)
456 ->execute()
457 ->fetch();
458
459 if ($editRecord !== false) {
460 BackendUtility::workspaceOL('pages', $editRecord);
461 }
462 }
463 // If the page was accessible, then let the user edit it.
464 if (is_array($editRecord) && $beUser->isInWebMount($editRecord['uid'])) {
465 // Setting JS code to open editing:
466 $this->js .= '
467 // Load page to edit:
468 window.setTimeout("top.loadEditId(' . (int)$editRecord['uid'] . ');", 500);
469 ';
470 // Checking page edit parameter:
471 if (!$beUser->getTSConfigVal('options.bookmark_onEditId_dontSetPageTree')) {
472 $bookmarkKeepExpanded = $beUser->getTSConfigVal('options.bookmark_onEditId_keepExistingExpanded');
473 // Expanding page tree:
474 BackendUtility::openPageTree((int)$editRecord['pid'], !$bookmarkKeepExpanded);
475 }
476 } else {
477 $this->js .= '
478 // Warning about page editing:
479 require(["TYPO3/CMS/Backend/Modal", "TYPO3/CMS/Backend/Severity"], function(Modal, Severity) {
480 Modal.show("", ' . GeneralUtility::quoteJSvalue(sprintf($this->getLanguageService()->getLL('noEditPage'), $editId)) . ', Severity.notice, [{
481 text: ' . GeneralUtility::quoteJSvalue($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:close')) . ',
482 active: true,
483 btnClass: "btn-info",
484 name: "cancel",
485 trigger: function () {
486 Modal.currentModal.trigger("modal-dismiss");
487 }
488 }])
489 });';
490 }
491 }
492 }
493
494 /**
495 * Sets the startup module from either GETvars module and modParams or user configuration.
496 *
497 * @return string the JavaScript code for the startup module
498 */
499 protected function setStartupModule()
500 {
501 $startModule = preg_replace('/[^[:alnum:]_]/', '', GeneralUtility::_GET('module'));
502 $startModuleParameters = '';
503 if (!$startModule) {
504 $beUser = $this->getBackendUser();
505 // start module on first login, will be removed once used the first time
506 if (isset($beUser->uc['startModuleOnFirstLogin'])) {
507 $startModule = $beUser->uc['startModuleOnFirstLogin'];
508 unset($beUser->uc['startModuleOnFirstLogin']);
509 $beUser->writeUC();
510 } elseif ($beUser->uc['startModule']) {
511 $startModule = $beUser->uc['startModule'];
512 }
513
514 // check if the start module has additional parameters, so a redirect to a specific
515 // action is possible
516 if (strpos($startModule, '->') !== false) {
517 list($startModule, $startModuleParameters) = explode('->', $startModule, 2);
518 }
519 }
520
521 $moduleParameters = GeneralUtility::_GET('modParams');
522 // if no GET parameters are set, check if there are parameters given from the UC
523 if (!$moduleParameters && $startModuleParameters) {
524 $moduleParameters = $startModuleParameters;
525 }
526
527 if ($startModule) {
528 return '
529 // start in module:
530 top.startInModule = [' . GeneralUtility::quoteJSvalue($startModule) . ', ' . GeneralUtility::quoteJSvalue($moduleParameters) . '];
531 ';
532 }
533 return '';
534 }
535
536 /**
537 * Adds a css snippet to the backend
538 *
539 * @param string $css Css snippet
540 * @throws \InvalidArgumentException
541 */
542 public function addCss($css)
543 {
544 if (!is_string($css)) {
545 throw new \InvalidArgumentException('parameter $css must be of type string', 1195129642);
546 }
547 $this->css .= $css;
548 }
549
550 /**
551 * Executes defined hooks functions for the given identifier.
552 *
553 * These hook identifiers are valid:
554 * + constructPostProcess
555 * + renderPreProcess
556 * + renderPostProcess
557 *
558 * @param string $identifier Specific hook identifier
559 * @param array $hookConfiguration Additional configuration passed to hook functions
560 */
561 protected function executeHook($identifier, array $hookConfiguration = [])
562 {
563 $options = &$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/backend.php'];
564 foreach ($options[$identifier] ?? [] as $hookFunction) {
565 GeneralUtility::callUserFunction($hookFunction, $hookConfiguration, $this);
566 }
567 }
568
569 /**
570 * loads all modules from the repository
571 * and renders it with a template
572 *
573 * @return string
574 */
575 protected function generateModuleMenu()
576 {
577 // get all modules except the user modules for the side menu
578 $moduleStorage = $this->backendModuleRepository->loadAllowedModules(['user', 'help']);
579
580 $view = $this->getFluidTemplateObject($this->templatePath . 'ModuleMenu/Main.html');
581 $view->assign('modules', $moduleStorage);
582 return $view->render();
583 }
584
585 /**
586 * Returns the Module menu for the AJAX request
587 *
588 * @param ServerRequestInterface $request
589 * @return ResponseInterface
590 */
591 public function getModuleMenu(ServerRequestInterface $request): ResponseInterface
592 {
593 return GeneralUtility::makeInstance(JsonResponse::class, ['menu' => $this->generateModuleMenu()]);
594 }
595
596 /**
597 * Returns the toolbar for the AJAX request
598 *
599 * @param ServerRequestInterface $request
600 * @return ResponseInterface
601 */
602 public function getTopbar(ServerRequestInterface $request): ResponseInterface
603 {
604 return GeneralUtility::makeInstance(JsonResponse::class, ['topbar' => $this->renderTopbar()]);
605 }
606
607 /**
608 * returns a new standalone view, shorthand function
609 *
610 * @param string $templatePathAndFileName optional the path to set the template path and filename
611 * @return \TYPO3\CMS\Fluid\View\StandaloneView
612 */
613 protected function getFluidTemplateObject($templatePathAndFileName = null)
614 {
615 $view = GeneralUtility::makeInstance(StandaloneView::class);
616 $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials')]);
617 if ($templatePathAndFileName) {
618 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templatePathAndFileName));
619 }
620 return $view;
621 }
622
623 /**
624 * Returns LanguageService
625 *
626 * @return \TYPO3\CMS\Core\Localization\LanguageService
627 */
628 protected function getLanguageService()
629 {
630 return $GLOBALS['LANG'];
631 }
632
633 /**
634 * Returns the current BE user.
635 *
636 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
637 */
638 protected function getBackendUser()
639 {
640 return $GLOBALS['BE_USER'];
641 }
642
643 /**
644 * Returns an instance of DocumentTemplate
645 *
646 * @return \TYPO3\CMS\Backend\Template\DocumentTemplate
647 */
648 protected function getDocumentTemplate()
649 {
650 return $GLOBALS['TBE_TEMPLATE'];
651 }
652 }