c82ab8ba33e4ee5be3279e5a7f74f5b3b3044c4c
[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');
160 $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Storage/Persistent', 'function(PersistentStorage) {
161 PersistentStorage.load(' . json_encode($this->getBackendUser()->uc) . ');
162 }');
163
164 // load debug console
165 $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/DebugConsole');
166
167 $this->pageRenderer->addInlineLanguageLabelFile('EXT:core/Resources/Private/Language/locallang_core.xlf');
168 $this->pageRenderer->addInlineLanguageLabelFile('EXT:core/Resources/Private/Language/locallang_misc.xlf');
169 $this->pageRenderer->addInlineLanguageLabelFile('EXT:backend/Resources/Private/Language/locallang_layout.xlf');
170 $this->pageRenderer->addInlineLanguageLabelFile('EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf');
171
172 $this->pageRenderer->addInlineLanguageLabelFile('EXT:core/Resources/Private/Language/debugger.xlf');
173 $this->pageRenderer->addInlineLanguageLabelFile('EXT:core/Resources/Private/Language/wizard.xlf');
174
175 $this->pageRenderer->addInlineSetting('ShowItem', 'moduleUrl', (string)$uriBuilder->buildUriFromRoute('show_item'));
176 $this->pageRenderer->addInlineSetting('RecordHistory', 'moduleUrl', (string)$uriBuilder->buildUriFromRoute('record_history'));
177 $this->pageRenderer->addInlineSetting('NewRecord', 'moduleUrl', (string)$uriBuilder->buildUriFromRoute('db_new'));
178 $this->pageRenderer->addInlineSetting('FormEngine', 'moduleUrl', (string)$uriBuilder->buildUriFromRoute('record_edit'));
179 $this->pageRenderer->addInlineSetting('RecordCommit', 'moduleUrl', (string)$uriBuilder->buildUriFromRoute('tce_db'));
180 $this->pageRenderer->addInlineSetting('WebLayout', 'moduleUrl', (string)$uriBuilder->buildUriFromRoute('web_layout'));
181
182 $this->css = '';
183
184 $this->initializeToolbarItems();
185 $this->executeHook('constructPostProcess');
186 }
187
188 /**
189 * Initialize toolbar item objects
190 *
191 * @throws \RuntimeException
192 */
193 protected function initializeToolbarItems()
194 {
195 $toolbarItemInstances = [];
196 foreach ($GLOBALS['TYPO3_CONF_VARS']['BE']['toolbarItems'] ?? [] as $className) {
197 $toolbarItemInstance = GeneralUtility::makeInstance($className);
198 if (!$toolbarItemInstance instanceof ToolbarItemInterface) {
199 throw new \RuntimeException(
200 'class ' . $className . ' is registered as toolbar item but does not implement'
201 . ToolbarItemInterface::class,
202 1415958218
203 );
204 }
205 $index = (int)$toolbarItemInstance->getIndex();
206 if ($index < 0 || $index > 100) {
207 throw new \RuntimeException(
208 'getIndex() must return an integer between 0 and 100',
209 1415968498
210 );
211 }
212 // Find next free position in array
213 while (array_key_exists($index, $toolbarItemInstances)) {
214 $index++;
215 }
216 $toolbarItemInstances[$index] = $toolbarItemInstance;
217 }
218 ksort($toolbarItemInstances);
219 $this->toolbarItems = $toolbarItemInstances;
220 }
221
222 /**
223 * Injects the request object for the current request or subrequest
224 * As this controller goes only through the render() method, it is rather simple for now
225 *
226 * @return ResponseInterface the response with the content
227 */
228 public function mainAction(): ResponseInterface
229 {
230 $this->render();
231 return new HtmlResponse($this->content);
232 }
233
234 /**
235 * Main function generating the BE scaffolding
236 */
237 protected function render()
238 {
239 $this->executeHook('renderPreProcess');
240
241 // Prepare the scaffolding, at this point extension may still add javascript and css
242 $view = $this->getFluidTemplateObject($this->templatePath . 'Backend/Main.html');
243
244 $view->assign('moduleMenu', $this->generateModuleMenu());
245 $view->assign('topbar', $this->renderTopbar());
246
247 /******************************************************
248 * Now put the complete backend document together
249 ******************************************************/
250 foreach ($this->cssFiles as $cssFileName => $cssFile) {
251 $this->pageRenderer->addCssFile($cssFile);
252 // Load additional css files to overwrite existing core styles
253 if (!empty($GLOBALS['TBE_STYLES']['stylesheets'][$cssFileName])) {
254 $this->pageRenderer->addCssFile($GLOBALS['TBE_STYLES']['stylesheets'][$cssFileName]);
255 }
256 }
257 if (!empty($this->css)) {
258 $this->pageRenderer->addCssInlineBlock('BackendInlineCSS', $this->css);
259 }
260 foreach ($this->jsFiles as $jsFile) {
261 $this->pageRenderer->addJsFile($jsFile);
262 }
263 $this->generateJavascript();
264 $this->pageRenderer->addJsInlineCode('BackendInlineJavascript', $this->js, false);
265
266 // Set document title:
267 $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] ? $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] . ' [TYPO3 CMS ' . TYPO3_version . ']' : 'TYPO3 CMS ' . TYPO3_version;
268 // Renders the module page
269 $this->content = $this->getDocumentTemplate()->render($title, $view->render());
270 $hookConfiguration = ['content' => &$this->content];
271 $this->executeHook('renderPostProcess', $hookConfiguration);
272 }
273
274 /**
275 * Renders the topbar, containing the backend logo, sitename etc.
276 *
277 * @return string
278 */
279 protected function renderTopbar()
280 {
281 $view = $this->getFluidTemplateObject($this->partialPath . 'Backend/Topbar.html');
282
283 // Extension Configuration to find the TYPO3 logo in the left corner
284 $extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('backend');
285 $logoPath = '';
286 if (!empty($extConf['backendLogo'])) {
287 $customBackendLogo = GeneralUtility::getFileAbsFileName($extConf['backendLogo']);
288 if (!empty($customBackendLogo)) {
289 $logoPath = $customBackendLogo;
290 }
291 }
292 // if no custom logo was set or the path is invalid, use the original one
293 if (empty($logoPath) || !file_exists($logoPath)) {
294 $logoPath = GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Public/Images/typo3_logo_orange.svg');
295 $logoWidth = 22;
296 $logoHeight = 22;
297 } else {
298 // set width/height for custom logo
299 $imageInfo = GeneralUtility::makeInstance(ImageInfo::class, $logoPath);
300 $logoWidth = $imageInfo->getWidth() ?? '22';
301 $logoHeight = $imageInfo->getHeight() ?? '22';
302
303 // High-resolution?
304 if (strpos($logoPath, '@2x.') !== false) {
305 $logoWidth /= 2;
306 $logoHeight /= 2;
307 }
308 }
309
310 $view->assign('logoUrl', PathUtility::getAbsoluteWebPath($logoPath));
311 $view->assign('logoWidth', $logoWidth);
312 $view->assign('logoHeight', $logoHeight);
313 $view->assign('applicationVersion', TYPO3_version);
314 $view->assign('siteName', $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
315 $view->assign('toolbar', $this->renderToolbar());
316
317 return $view->render();
318 }
319
320 /**
321 * Renders the items in the top toolbar
322 *
323 * @return string top toolbar elements as HTML
324 */
325 protected function renderToolbar()
326 {
327 $toolbar = [];
328 foreach ($this->toolbarItems as $toolbarItem) {
329 /** @var \TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface $toolbarItem */
330 if ($toolbarItem->checkAccess()) {
331 $hasDropDown = (bool)$toolbarItem->hasDropDown();
332 $additionalAttributes = (array)$toolbarItem->getAdditionalAttributes();
333
334 $liAttributes = [];
335
336 // Merge class: Add dropdown class if hasDropDown, add classes from additional attributes
337 $classes = [];
338 $classes[] = 'toolbar-item';
339 $classes[] = 't3js-toolbar-item';
340 if (isset($additionalAttributes['class'])) {
341 $classes[] = $additionalAttributes['class'];
342 unset($additionalAttributes['class']);
343 }
344 $liAttributes['class'] = implode(' ', $classes);
345
346 // Add further attributes
347 foreach ($additionalAttributes as $name => $value) {
348 $liAttributes[$name] = $value;
349 }
350
351 // Create a unique id from class name
352 $fullyQualifiedClassName = \get_class($toolbarItem);
353 $className = GeneralUtility::underscoredToLowerCamelCase($fullyQualifiedClassName);
354 $className = GeneralUtility::camelCaseToLowerCaseUnderscored($className);
355 $className = str_replace(['_', '\\'], '-', $className);
356 $liAttributes['id'] = $className;
357
358 // Create data attribute identifier
359 $shortName = substr($fullyQualifiedClassName, strrpos($fullyQualifiedClassName, '\\') + 1);
360 $dataToolbarIdentifier = GeneralUtility::camelCaseToLowerCaseUnderscored($shortName);
361 $dataToolbarIdentifier = str_replace('_', '-', $dataToolbarIdentifier);
362 $liAttributes['data-toolbar-identifier'] = $dataToolbarIdentifier;
363
364 $toolbar[] = '<li ' . GeneralUtility::implodeAttributes($liAttributes, true) . '>';
365
366 if ($hasDropDown) {
367 $toolbar[] = '<a href="#" class="toolbar-item-link dropdown-toggle" data-toggle="dropdown">';
368 $toolbar[] = $toolbarItem->getItem();
369 $toolbar[] = '</a>';
370 $toolbar[] = '<div class="dropdown-menu" role="menu">';
371 $toolbar[] = $toolbarItem->getDropDown();
372 $toolbar[] = '</div>';
373 } else {
374 $toolbar[] = $toolbarItem->getItem();
375 }
376 $toolbar[] = '</li>';
377 }
378 }
379 return implode(LF, $toolbar);
380 }
381
382 /**
383 * Generates the JavaScript code for the backend.
384 */
385 protected function generateJavascript()
386 {
387 $beUser = $this->getBackendUser();
388 // Needed for FormEngine manipulation (date picker)
389 $dateFormat = ($GLOBALS['TYPO3_CONF_VARS']['SYS']['USdateFormat'] ? ['MM-DD-YYYY', 'HH:mm MM-DD-YYYY'] : ['DD-MM-YYYY', 'HH:mm DD-MM-YYYY']);
390 $this->pageRenderer->addInlineSetting('DateTimePicker', 'DateFormat', $dateFormat);
391
392 // If another page module was specified, replace the default Page module with the new one
393 $newPageModule = trim($beUser->getTSConfig()['options.']['overridePageModule'] ?? '');
394 $pageModule = BackendUtility::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
395 if (!$beUser->check('modules', $pageModule)) {
396 $pageModule = '';
397 }
398 $t3Configuration = [
399 'username' => htmlspecialchars($beUser->user['username']),
400 'pageModule' => $pageModule,
401 'inWorkspace' => $beUser->workspace !== 0,
402 'showRefreshLoginPopup' => (bool)($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup'] ?? false)
403 ];
404 $this->js .= '
405 TYPO3.configuration = ' . json_encode($t3Configuration) . ';
406 /**
407 * Frameset Module object
408 *
409 * Used in main modules with a frameset for submodules to keep the ID between modules
410 * Typically that is set by something like this in a Web>* sub module:
411 * if (top.fsMod) top.fsMod.recentIds["web"] = "\'.(int)$this->id.\'";
412 * if (top.fsMod) top.fsMod.recentIds["file"] = "...(file reference/string)...";
413 */
414 var fsMod = {
415 recentIds: [], // used by frameset modules to track the most recent used id for list frame.
416 navFrameHighlightedID: [], // used by navigation frames to track which row id was highlighted last time
417 currentBank: "0"
418 };
419
420 top.goToModule = function(modName, cMR_flag, addGetVars) {
421 TYPO3.ModuleMenu.App.showModule(modName, addGetVars);
422 }
423 ' . $this->setStartupModule();
424 // Check editing of page:
425 $this->handlePageEditing();
426 }
427
428 /**
429 * Checking if the "&edit" variable was sent so we can open it for editing the page.
430 */
431 protected function handlePageEditing()
432 {
433 $beUser = $this->getBackendUser();
434 $userTsConfig = $this->getBackendUser()->getTSConfig();
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 (!($userTsConfig['options.']['bookmark_onEditId_dontSetPageTree'] ?? false)) {
478 $bookmarkKeepExpanded = (bool)($userTsConfig['options.']['bookmark_onEditId_keepExistingExpanded'] ?? false);
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:core/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 }