‪TYPO3CMS  11.5
ModuleLoader.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
26 
33 {
41  public function ‪validateSortAndInitializeModules(array $modules): array
42  {
43  if (empty($modules)) {
44  return [];
45  }
46  foreach ($modules as $identifier => $configuration) {
47  if (empty($configuration) || !is_array($configuration)) {
49  'Missing configuration for module "' . $identifier . '".',
50  1519490105
51  );
52  }
53  if (empty($configuration['module']) ||
54  !is_string($configuration['module']) ||
55  !class_exists($configuration['module']) ||
56  !is_subclass_of(
57  $configuration['module'],
58  ModuleInterface::class,
59  true
60  )
61  ) {
63  'The module "' .
64  $identifier .
65  '" defines an invalid module class. Ensure the class exists and implements the "' .
66  ModuleInterface::class .
67  '".',
68  1519490112
69  );
70  }
71  }
72 
73  $orderedModules = GeneralUtility::makeInstance(DependencyOrderingService::class)->orderByDependencies(
74  $modules
75  );
76 
77  $moduleInstances = [];
78  foreach ($orderedModules as $moduleConfiguration) {
79  $module = GeneralUtility::makeInstance($moduleConfiguration['module']);
80  if (
81  $module instanceof ‪ModuleInterface
82  && (
83  ($module instanceof ‪ConfigurableInterface && $module->‪isEnabled())
84  || !($module instanceof ‪ConfigurableInterface)
85  )
86  ) {
87  $moduleInstances[$module->getIdentifier()] = $module;
88  }
89  if ($module instanceof ‪SubmoduleProviderInterface) {
90  $subModuleInstances = $this->‪validateSortAndInitializeModules($moduleConfiguration['submodules'] ?? []);
91  $module->setSubModules($subModuleInstances);
92  }
93  }
94  return $moduleInstances;
95  }
96 }
‪TYPO3\CMS\Adminpanel\Service\ModuleLoader
Definition: ModuleLoader.php:33
‪TYPO3\CMS\Adminpanel\ModuleApi\ConfigurableInterface
Definition: ConfigurableInterface.php:29
‪TYPO3\CMS\Adminpanel\ModuleApi\ConfigurableInterface\isEnabled
‪bool isEnabled()
‪TYPO3\CMS\Adminpanel\Service
Definition: ConfigurationService.php:18
‪TYPO3\CMS\Adminpanel\Exceptions\InvalidConfigurationException
Definition: InvalidConfigurationException.php:23
‪TYPO3\CMS\Core\Service\DependencyOrderingService
Definition: DependencyOrderingService.php:32
‪TYPO3\CMS\Adminpanel\ModuleApi\ModuleInterface
Definition: ModuleInterface.php:26
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Adminpanel\ModuleApi\SubmoduleProviderInterface
Definition: SubmoduleProviderInterface.php:30
‪TYPO3\CMS\Adminpanel\Service\ModuleLoader\validateSortAndInitializeModules
‪TYPO3 CMS Adminpanel ModuleApi ModuleInterface[] validateSortAndInitializeModules(array $modules)
Definition: ModuleLoader.php:41