Commit 75b261dc authored by Oliver Hader's avatar Oliver Hader Committed by Oliver Bartsch
Browse files

[TASK] Avoid using public property ModuleLoader::$modules

Changes read-access to modules from `ModuleLoader::$modules`
to `ModuleLoader::getModules()`.

Resolves: #95851
Releases: master
Change-Id: I011f014f6d1c70051e269b696b00a6a7c5c77a6e
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72026

Reviewed-by: Oliver Hader's avatarOliver Hader <oliver.hader@typo3.org>
Reviewed-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Simon Gilli's avatarSimon Gilli <typo3@gilbertsoft.org>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Tested-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
parent 288e88db
......@@ -651,9 +651,9 @@ class ShortcutRepository
if (str_contains($moduleName, '_')) {
[$mainModule, $subModule] = explode('_', $moduleName, 2);
$iconIdentifier = $this->moduleLoader->modules[$mainModule]['sub'][$subModule]['iconIdentifier'] ?? '';
$iconIdentifier = $this->moduleLoader->getModules()[$mainModule]['sub'][$subModule]['iconIdentifier'] ?? '';
} elseif ($moduleName !== '') {
$iconIdentifier = $this->moduleLoader->modules[$moduleName]['iconIdentifier'] ?? '';
$iconIdentifier = $this->moduleLoader->getModules()[$moduleName]['iconIdentifier'] ?? '';
}
if (!$iconIdentifier) {
......
......@@ -112,7 +112,7 @@ class AboutController
protected function getModulesData(): array
{
$mainModulesData = [];
foreach ($this->moduleLoader->modules as $moduleName => $moduleInfo) {
foreach ($this->moduleLoader->getModules() as $moduleName => $moduleInfo) {
$moduleLabels = $this->moduleLoader->getLabelsForModule($moduleName);
$mainModuleData = [
'name' => $moduleName,
......@@ -134,12 +134,12 @@ class AboutController
*/
protected function getSubModuleData(string $moduleName): array
{
if (empty($this->moduleLoader->modules[$moduleName]['sub'])) {
if (empty($this->moduleLoader->getModules()[$moduleName]['sub'])) {
return [];
}
$subModulesData = [];
foreach ($this->moduleLoader->modules[$moduleName]['sub'] as $subModuleName => $subModuleInfo) {
foreach ($this->moduleLoader->getModules()[$moduleName]['sub'] ?? [] as $subModuleName => $subModuleInfo) {
$moduleLabels = $this->moduleLoader->getLabelsForModule($moduleName . '_' . $subModuleName);
$subModuleData = [];
$subModuleData['name'] = $subModuleName;
......
......@@ -414,7 +414,7 @@ class BackendController
protected function determineFirstAvailableBackendModule(): string
{
foreach ($this->moduleLoader->modules as $mainMod => $modData) {
foreach ($this->moduleLoader->getModules() as $modData) {
$hasSubmodules = !empty($modData['sub']) && is_array($modData['sub']);
$isStandalone = $modData['standalone'] ?? false;
if ($isStandalone) {
......
......@@ -377,8 +377,8 @@ class PageLayoutController
if ($this->pageinfo['doktype'] == PageRepository::DOKTYPE_SYSFOLDER) {
$moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class);
$moduleLoader->load($GLOBALS['TBE_MODULES']);
$modules = $moduleLoader->modules;
if (is_array($modules['web']['sub']['list'])) {
$modules = $moduleLoader->getModules();
if (is_array($modules['web']['sub']['list'] ?? null)) {
$title = $lang->getLL('goToListModule');
$message = '<p>' . $lang->getLL('goToListModuleMessage') . '</p>';
$message .= '<a class="btn btn-info" data-dispatch-action="TYPO3.ModuleMenu.showModule" data-dispatch-args-list="web_list">'
......
......@@ -243,7 +243,7 @@ class BackendModuleRepository implements SingletonInterface
$moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class);
$moduleLoader->observeWorkspaces = true;
$moduleLoader->load($GLOBALS['TBE_MODULES']);
$loadedModules = $moduleLoader->modules;
$loadedModules = $moduleLoader->getModules();
$modules = [];
......
......@@ -97,7 +97,7 @@ class TableManualRepository
// Backend Modules
$loadModules = GeneralUtility::makeInstance(ModuleLoader::class);
$loadModules->load($GLOBALS['TBE_MODULES']);
foreach ($loadModules->modules as $mainMod => $info) {
foreach ($loadModules->getModules() as $mainMod => $info) {
$cshKey = '_MOD_' . $mainMod;
if ($cshKeys[$cshKey] ?? '') {
$lang->loadSingleTableDescription($cshKey);
......
......@@ -35,7 +35,10 @@ class ModuleLoader
/**
* After the init() function this array will contain the structure of available modules for the backend user.
*
* @var array
* @var array<string, array|bool|string>
* @todo Restrict property visibility to `protected` in TYPO3 v12.0
* @internal
* @private
*/
public $modules = [];
......@@ -80,6 +83,14 @@ class ModuleLoader
*/
protected $moduleLabels = [];
/**
* @return array<string, array|bool|string>
*/
public function getModules(): array
{
return $this->modules;
}
/**
* Init.
* The outcome of the load() function will be a $this->modules array populated with the backend module structure available to the BE_USER
......@@ -304,7 +315,7 @@ class ModuleLoader
* Returns an array where the keys are names of the module and the values may be TRUE (only module) or an array (of submodules)
*
* @param array $arr ModuleArray ($TBE_MODULES)
* @return array Output structure with available modules
* @return array<string, int|string> Output structure with available modules
*/
public function parseModulesArray($arr)
{
......
......@@ -258,9 +258,9 @@ class TcaItemsProcessorFunctions
$subModule = $moduleArray[1] ?? '';
// Icon:
if (!empty($subModule)) {
$icon = $moduleLoader->modules[$mainModule]['sub'][$subModule]['iconIdentifier'] ?? '';
$icon = $moduleLoader->getModules()[$mainModule]['sub'][$subModule]['iconIdentifier'] ?? '';
} else {
$icon = $moduleLoader->modules[$module]['iconIdentifier'] ?? '';
$icon = $moduleLoader->getModules()[$module]['iconIdentifier'] ?? '';
}
// Add help text
$helpText = [
......
......@@ -158,11 +158,11 @@ class TcaItemsProcessorFunctionsTest extends UnitTestCase
$moduleLoaderProphecy->modListGroup = [
'aModule',
];
$moduleLoaderProphecy->modules = [
$moduleLoaderProphecy->getModules()->willReturn([
'aModule' => [
'iconIdentifier' => 'empty-empty',
],
];
]);
$moduleLoaderProphecy->getLabelsForModule('aModule')->shouldBeCalled()->willReturn([
'shortdescription' => 'aModuleTabLabel',
'description' => 'aModuleTabDescription',
......@@ -200,11 +200,11 @@ class TcaItemsProcessorFunctionsTest extends UnitTestCase
$moduleLoaderProphecy->modListUser = [
'bModule',
];
$moduleLoaderProphecy->modules = [
$moduleLoaderProphecy->getModules()->willReturn([
'bModule' => [
'iconIdentifier' => 'empty-empty',
],
];
]);
$moduleLoaderProphecy->getLabelsForModule('bModule')->shouldBeCalled()->willReturn([
'shortdescription' => 'bModuleTabLabel',
'description' => 'bModuleTabDescription',
......
......@@ -750,7 +750,7 @@ class SetupModuleController
$loadModules->observeWorkspaces = true;
$loadModules->load($GLOBALS['TBE_MODULES']);
$startModuleSelect = '<option value="">' . htmlspecialchars($this->getLanguageService()->getLL('startModule.firstInMenu')) . '</option>';
foreach ($loadModules->modules as $mainMod => $modData) {
foreach ($loadModules->getModules() as $mainMod => $modData) {
$hasSubmodules = !empty($modData['sub']) && is_array($modData['sub']);
$isStandalone = $modData['standalone'] ?? false;
if ($hasSubmodules || $isStandalone) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment