From 7e2a5da7a47c47da34be57dcc90e000387025c61 Mon Sep 17 00:00:00 2001 From: Andreas Fernandez <a.fernandez@scripting-base.de> Date: Tue, 14 Apr 2020 16:13:08 +0200 Subject: [PATCH] [BUGFIX] Load the correct "first module" The start up option "First module in menu" is a misleading in some ways. The select box e.g. has "dashboard" as first selectable option, but in such cases the "help_AboutAbout" module is loaded instead, for example. This is due the fact the first module is determined via querying the DOM for the first element matching the selector `.t3js-modulemenu-action[data-link]`. The behavior is now changed to load the first module as listed in the previously mentioned select box. Resolves: #91028 Releases: master Change-Id: I669a9b146f76f2513c51ff5f48128a1ea8b0c0a7 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/64164 Tested-by: Richard Haeser <richard@maxserv.com> Tested-by: Georg Ringer <georg.ringer@gmail.com> Reviewed-by: Richard Haeser <richard@maxserv.com> Reviewed-by: Georg Ringer <georg.ringer@gmail.com> --- .../Classes/Controller/BackendController.php | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/typo3/sysext/backend/Classes/Controller/BackendController.php b/typo3/sysext/backend/Classes/Controller/BackendController.php index 7a0825d02f79..a1c70588b75a 100644 --- a/typo3/sysext/backend/Classes/Controller/BackendController.php +++ b/typo3/sysext/backend/Classes/Controller/BackendController.php @@ -18,6 +18,7 @@ namespace TYPO3\CMS\Backend\Controller; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Backend\Domain\Repository\Module\BackendModuleRepository; +use TYPO3\CMS\Backend\Module\ModuleLoader; use TYPO3\CMS\Backend\Routing\UriBuilder; use TYPO3\CMS\Backend\Template\ModuleTemplate; use TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface; @@ -452,6 +453,8 @@ class BackendController $beUser->writeUC(); } elseif ($beUser->uc['startModule']) { $startModule = $beUser->uc['startModule']; + } else { + $startModule = $this->determineFirstAvailableBackendModule(); } // check if the start module has additional parameters, so a redirect to a specific @@ -476,6 +479,28 @@ class BackendController return ''; } + protected function determineFirstAvailableBackendModule(): string + { + $loadModules = GeneralUtility::makeInstance(ModuleLoader::class); + $loadModules->observeWorkspaces = true; + $loadModules->load($GLOBALS['TBE_MODULES']); + + foreach ($loadModules->modules as $mainMod => $modData) { + $hasSubmodules = !empty($modData['sub']) && is_array($modData['sub']); + $isStandalone = $modData['standalone'] ?? false; + if ($isStandalone) { + return $modData['name']; + } + + if ($hasSubmodules) { + $firstSubmodule = reset($modData['sub']); + return $firstSubmodule['name']; + } + } + + return ''; + } + /** * Adds a css snippet to the backend * -- GitLab