[BUGFIX] Check if file exists for backend logo
[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 TYPO3\CMS\Backend\Domain\Repository\Module\BackendModuleRepository;
19 use TYPO3\CMS\Backend\Module\ModuleLoader;
20 use TYPO3\CMS\Backend\Routing\UriBuilder;
21 use TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface;
22 use TYPO3\CMS\Backend\Utility\BackendUtility;
23 use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
24 use TYPO3\CMS\Core\Database\ConnectionPool;
25 use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
26 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
27 use TYPO3\CMS\Core\Http\HtmlResponse;
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 InfoWindow
155 $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/InfoWindow');
156
157 // load ContextMenu
158 $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
159
160 // load the storage API and fill the UC into the PersistentStorage, so no additional AJAX call is needed
161 $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Storage');
162 $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Storage/Persistent', 'function(PersistentStorage) {
163 PersistentStorage.load(' . json_encode($this->getBackendUser()->uc) . ');
164 }');
165
166 // load debug console
167 $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/DebugConsole');
168
169 $this->pageRenderer->addInlineLanguageLabelFile('EXT:lang/Resources/Private/Language/locallang_core.xlf');
170 $this->pageRenderer->addInlineLanguageLabelFile('EXT:lang/Resources/Private/Language/locallang_misc.xlf');
171 $this->pageRenderer->addInlineLanguageLabelFile('EXT:backend/Resources/Private/Language/locallang_layout.xlf');
172
173 $this->pageRenderer->addInlineLanguageLabelFile('EXT:core/Resources/Private/Language/debugger.xlf');
174 $this->pageRenderer->addInlineLanguageLabelFile('EXT:core/Resources/Private/Language/wizard.xlf');
175
176 $this->pageRenderer->addInlineSetting('ShowItem', 'moduleUrl', (string)$uriBuilder->buildUriFromRoute('show_item'));
177 $this->pageRenderer->addInlineSetting('RecordHistory', 'moduleUrl', (string)$uriBuilder->buildUriFromRoute('record_history'));
178 $this->pageRenderer->addInlineSetting('NewRecord', 'moduleUrl', (string)$uriBuilder->buildUriFromRoute('db_new'));
179 $this->pageRenderer->addInlineSetting('FormEngine', 'moduleUrl', (string)$uriBuilder->buildUriFromRoute('record_edit'));
180 $this->pageRenderer->addInlineSetting('RecordCommit', 'moduleUrl', (string)$uriBuilder->buildUriFromRoute('tce_db'));
181 $this->pageRenderer->addInlineSetting('WebLayout', 'moduleUrl', (string)$uriBuilder->buildUriFromRoute('web_layout'));
182
183 $this->css = '';
184
185 $this->initializeToolbarItems();
186 $this->executeHook('constructPostProcess');
187 }
188
189 /**
190 * Initialize toolbar item objects
191 *
192 * @throws \RuntimeException
193 */
194 protected function initializeToolbarItems()
195 {
196 $toolbarItemInstances = [];
197 foreach ($GLOBALS['TYPO3_CONF_VARS']['BE']['toolbarItems'] ?? [] as $className) {
198 $toolbarItemInstance = GeneralUtility::makeInstance($className);
199 if (!$toolbarItemInstance instanceof ToolbarItemInterface) {
200 throw new \RuntimeException(
201 'class ' . $className . ' is registered as toolbar item but does not implement'
202 . ToolbarItemInterface::class,
203 1415958218
204 );
205 }
206 $index = (int)$toolbarItemInstance->getIndex();
207 if ($index < 0 || $index > 100) {
208 throw new \RuntimeException(
209 'getIndex() must return an integer between 0 and 100',
210 1415968498
211 );
212 }
213 // Find next free position in array
214 while (array_key_exists($index, $toolbarItemInstances)) {
215 $index++;
216 }
217 $toolbarItemInstances[$index] = $toolbarItemInstance;
218 }
219 ksort($toolbarItemInstances);
220 $this->toolbarItems = $toolbarItemInstances;
221 }
222
223 /**
224 * Injects the request object for the current request or subrequest
225 * As this controller goes only through the render() method, it is rather simple for now
226 *
227 * @return ResponseInterface the response with the content
228 */
229 public function mainAction(): ResponseInterface
230 {
231 $this->render();
232 return new HtmlResponse($this->content);
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) || !file_exists($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 $fullyQualifiedClassName = \get_class($toolbarItem);
354 $className = GeneralUtility::underscoredToLowerCamelCase($fullyQualifiedClassName);
355 $className = GeneralUtility::camelCaseToLowerCaseUnderscored($className);
356 $className = str_replace(['_', '\\'], '-', $className);
357 $liAttributes['id'] = $className;
358
359 // Create data attribute identifier
360 $shortName = substr($fullyQualifiedClassName, strrpos($fullyQualifiedClassName, '\\') + 1);
361 $dataToolbarIdentifier = GeneralUtility::camelCaseToLowerCaseUnderscored($shortName);
362 $dataToolbarIdentifier = str_replace('_', '-', $dataToolbarIdentifier);
363 $liAttributes['data-toolbar-identifier'] = $dataToolbarIdentifier;
364
365 $toolbar[] = '<li ' . GeneralUtility::implodeAttributes($liAttributes, true) . '>';
366
367 if ($hasDropDown) {
368 $toolbar[] = '<a href="#" class="toolbar-item-link dropdown-toggle" data-toggle="dropdown">';
369 $toolbar[] = $toolbarItem->getItem();
370 $toolbar[] = '</a>';
371 $toolbar[] = '<div class="dropdown-menu" role="menu">';
372 $toolbar[] = $toolbarItem->getDropDown();
373 $toolbar[] = '</div>';
374 } else {
375 $toolbar[] = $toolbarItem->getItem();
376 }
377 $toolbar[] = '</li>';
378 }
379 }
380 return implode(LF, $toolbar);
381 }
382
383 /**
384 * Generates the JavaScript code for the backend.
385 */
386 protected function generateJavascript()
387 {
388 $beUser = $this->getBackendUser();
389 // Needed for FormEngine manipulation (date picker)
390 $dateFormat = ($GLOBALS['TYPO3_CONF_VARS']['SYS']['USdateFormat'] ? ['MM-DD-YYYY', 'HH:mm MM-DD-YYYY'] : ['DD-MM-YYYY', 'HH:mm DD-MM-YYYY']);
391 $this->pageRenderer->addInlineSetting('DateTimePicker', 'DateFormat', $dateFormat);
392
393 // If another page module was specified, replace the default Page module with the new one
394 $newPageModule = trim($beUser->getTSConfigVal('options.overridePageModule'));
395 $pageModule = BackendUtility::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
396 if (!$beUser->check('modules', $pageModule)) {
397 $pageModule = '';
398 }
399 $t3Configuration = [
400 'username' => htmlspecialchars($beUser->user['username']),
401 'pageModule' => $pageModule,
402 'inWorkspace' => $beUser->workspace !== 0,
403 'showRefreshLoginPopup' => (bool)($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup'] ?? false)
404 ];
405 $this->js .= '
406 TYPO3.configuration = ' . json_encode($t3Configuration) . ';
407 /**
408 * Frameset Module object
409 *
410 * Used in main modules with a frameset for submodules to keep the ID between modules
411 * Typically that is set by something like this in a Web>* sub module:
412 * if (top.fsMod) top.fsMod.recentIds["web"] = "\'.(int)$this->id.\'";
413 * if (top.fsMod) top.fsMod.recentIds["file"] = "...(file reference/string)...";
414 */
415 var fsMod = {
416 recentIds: [], // used by frameset modules to track the most recent used id for list frame.
417 navFrameHighlightedID: [], // used by navigation frames to track which row id was highlighted last time
418 currentBank: "0"
419 };
420
421 top.goToModule = function(modName, cMR_flag, addGetVars) {
422 TYPO3.ModuleMenu.App.showModule(modName, addGetVars);
423 }
424 ' . $this->setStartupModule();
425 // Check editing of page:
426 $this->handlePageEditing();
427 }
428
429 /**
430 * Checking if the "&edit" variable was sent so we can open it for editing the page.
431 */
432 protected function handlePageEditing()
433 {
434 $beUser = $this->getBackendUser();
435 // EDIT page:
436 $editId = preg_replace('/[^[:alnum:]_]/', '', GeneralUtility::_GET('edit'));
437 if ($editId) {
438 // Looking up the page to edit, checking permissions:
439 $where = ' AND (' . $beUser->getPagePermsClause(Permission::PAGE_EDIT) . ' OR ' . $beUser->getPagePermsClause(Permission::CONTENT_EDIT) . ')';
440 if (MathUtility::canBeInterpretedAsInteger($editId)) {
441 $editRecord = BackendUtility::getRecordWSOL('pages', $editId, '*', $where);
442 } else {
443 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
444 $queryBuilder->getRestrictions()
445 ->removeAll()
446 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
447 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
448
449 $editRecord = $queryBuilder->select('*')
450 ->from('pages')
451 ->where(
452 $queryBuilder->expr()->eq(
453 'alias',
454 $queryBuilder->createNamedParameter($editId, \PDO::PARAM_STR)
455 ),
456 $queryBuilder->expr()->orX(
457 $beUser->getPagePermsClause(Permission::PAGE_EDIT),
458 $beUser->getPagePermsClause(Permission::CONTENT_EDIT)
459 )
460 )
461 ->setMaxResults(1)
462 ->execute()
463 ->fetch();
464
465 if ($editRecord !== false) {
466 BackendUtility::workspaceOL('pages', $editRecord);
467 }
468 }
469 // If the page was accessible, then let the user edit it.
470 if (is_array($editRecord) && $beUser->isInWebMount($editRecord['uid'])) {
471 // Setting JS code to open editing:
472 $this->js .= '
473 // Load page to edit:
474 window.setTimeout("top.loadEditId(' . (int)$editRecord['uid'] . ');", 500);
475 ';
476 // Checking page edit parameter:
477 if (!$beUser->getTSConfigVal('options.bookmark_onEditId_dontSetPageTree')) {
478 $bookmarkKeepExpanded = $beUser->getTSConfigVal('options.bookmark_onEditId_keepExistingExpanded');
479 // Expanding page tree:
480 BackendUtility::openPageTree((int)$editRecord['pid'], !$bookmarkKeepExpanded);
481 }
482 } else {
483 $this->js .= '
484 // Warning about page editing:
485 require(["TYPO3/CMS/Backend/Modal", "TYPO3/CMS/Backend/Severity"], function(Modal, Severity) {
486 Modal.show("", ' . GeneralUtility::quoteJSvalue(sprintf($this->getLanguageService()->getLL('noEditPage'), $editId)) . ', Severity.notice, [{
487 text: ' . GeneralUtility::quoteJSvalue($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:close')) . ',
488 active: true,
489 btnClass: "btn-info",
490 name: "cancel",
491 trigger: function () {
492 Modal.currentModal.trigger("modal-dismiss");
493 }
494 }])
495 });';
496 }
497 }
498 }
499
500 /**
501 * Sets the startup module from either GETvars module and modParams or user configuration.
502 *
503 * @return string the JavaScript code for the startup module
504 */
505 protected function setStartupModule()
506 {
507 $startModule = preg_replace('/[^[:alnum:]_]/', '', GeneralUtility::_GET('module'));
508 $startModuleParameters = '';
509 if (!$startModule) {
510 $beUser = $this->getBackendUser();
511 // start module on first login, will be removed once used the first time
512 if (isset($beUser->uc['startModuleOnFirstLogin'])) {
513 $startModule = $beUser->uc['startModuleOnFirstLogin'];
514 unset($beUser->uc['startModuleOnFirstLogin']);
515 $beUser->writeUC();
516 } elseif ($beUser->uc['startModule']) {
517 $startModule = $beUser->uc['startModule'];
518 }
519
520 // check if the start module has additional parameters, so a redirect to a specific
521 // action is possible
522 if (strpos($startModule, '->') !== false) {
523 list($startModule, $startModuleParameters) = explode('->', $startModule, 2);
524 }
525 }
526
527 $moduleParameters = GeneralUtility::_GET('modParams');
528 // if no GET parameters are set, check if there are parameters given from the UC
529 if (!$moduleParameters && $startModuleParameters) {
530 $moduleParameters = $startModuleParameters;
531 }
532
533 if ($startModule) {
534 return '
535 // start in module:
536 top.startInModule = [' . GeneralUtility::quoteJSvalue($startModule) . ', ' . GeneralUtility::quoteJSvalue($moduleParameters) . '];
537 ';
538 }
539 return '';
540 }
541
542 /**
543 * Adds a css snippet to the backend
544 *
545 * @param string $css Css snippet
546 * @throws \InvalidArgumentException
547 */
548 public function addCss($css)
549 {
550 if (!is_string($css)) {
551 throw new \InvalidArgumentException('parameter $css must be of type string', 1195129642);
552 }
553 $this->css .= $css;
554 }
555
556 /**
557 * Executes defined hooks functions for the given identifier.
558 *
559 * These hook identifiers are valid:
560 * + constructPostProcess
561 * + renderPreProcess
562 * + renderPostProcess
563 *
564 * @param string $identifier Specific hook identifier
565 * @param array $hookConfiguration Additional configuration passed to hook functions
566 */
567 protected function executeHook($identifier, array $hookConfiguration = [])
568 {
569 $options = &$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/backend.php'];
570 foreach ($options[$identifier] ?? [] as $hookFunction) {
571 GeneralUtility::callUserFunction($hookFunction, $hookConfiguration, $this);
572 }
573 }
574
575 /**
576 * loads all modules from the repository
577 * and renders it with a template
578 *
579 * @return string
580 */
581 protected function generateModuleMenu()
582 {
583 // get all modules except the user modules for the side menu
584 $moduleStorage = $this->backendModuleRepository->loadAllowedModules(['user', 'help']);
585
586 $view = $this->getFluidTemplateObject($this->templatePath . 'ModuleMenu/Main.html');
587 $view->assign('modules', $moduleStorage);
588 return $view->render();
589 }
590
591 /**
592 * Returns the Module menu for the AJAX request
593 *
594 * @return ResponseInterface
595 */
596 public function getModuleMenu(): ResponseInterface
597 {
598 return new JsonResponse(['menu' => $this->generateModuleMenu()]);
599 }
600
601 /**
602 * Returns the toolbar for the AJAX request
603 *
604 * @return ResponseInterface
605 */
606 public function getTopbar(): ResponseInterface
607 {
608 return new JsonResponse(['topbar' => $this->renderTopbar()]);
609 }
610
611 /**
612 * returns a new standalone view, shorthand function
613 *
614 * @param string $templatePathAndFileName optional the path to set the template path and filename
615 * @return \TYPO3\CMS\Fluid\View\StandaloneView
616 */
617 protected function getFluidTemplateObject($templatePathAndFileName = null)
618 {
619 $view = GeneralUtility::makeInstance(StandaloneView::class);
620 $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials')]);
621 if ($templatePathAndFileName) {
622 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templatePathAndFileName));
623 }
624 return $view;
625 }
626
627 /**
628 * Returns LanguageService
629 *
630 * @return \TYPO3\CMS\Core\Localization\LanguageService
631 */
632 protected function getLanguageService()
633 {
634 return $GLOBALS['LANG'];
635 }
636
637 /**
638 * Returns the current BE user.
639 *
640 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
641 */
642 protected function getBackendUser()
643 {
644 return $GLOBALS['BE_USER'];
645 }
646
647 /**
648 * Returns an instance of DocumentTemplate
649 *
650 * @return \TYPO3\CMS\Backend\Template\DocumentTemplate
651 */
652 protected function getDocumentTemplate()
653 {
654 return $GLOBALS['TBE_TEMPLATE'];
655 }
656 }