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