‪TYPO3CMS  9.5
ModuleLoader.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
25 
32 {
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 (!is_string($configuration['module']) ||
54  empty($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:32
‪TYPO3\CMS\Adminpanel\ModuleApi\ConfigurableInterface
Definition: ConfigurableInterface.php:28
‪TYPO3\CMS\Adminpanel\ModuleApi\ConfigurableInterface\isEnabled
‪bool isEnabled()
‪TYPO3\CMS\Adminpanel\Service
Definition: ConfigurationService.php:4
‪TYPO3\CMS\Adminpanel\Exceptions\InvalidConfigurationException
Definition: InvalidConfigurationException.php:23
‪TYPO3\CMS\Core\Service\DependencyOrderingService
Definition: DependencyOrderingService.php:31
‪TYPO3\CMS\Adminpanel\ModuleApi\ModuleInterface
Definition: ModuleInterface.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Adminpanel\ModuleApi\SubmoduleProviderInterface
Definition: SubmoduleProviderInterface.php:29
‪TYPO3\CMS\Adminpanel\Service\ModuleLoader\validateSortAndInitializeModules
‪TYPO3 CMS Adminpanel ModuleApi ModuleInterface[] validateSortAndInitializeModules(array $modules)
Definition: ModuleLoader.php:41