‪TYPO3CMS  10.4
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 {
34 
42  public function ‪validateSortAndInitializeModules(array $modules): array
43  {
44  if (empty($modules)) {
45  return [];
46  }
47  foreach ($modules as $identifier => $configuration) {
48  if (empty($configuration) || !is_array($configuration)) {
50  'Missing configuration for module "' . $identifier . '".',
51  1519490105
52  );
53  }
54  if (!is_string($configuration['module']) ||
55  empty($configuration['module']) ||
56  !class_exists($configuration['module']) ||
57  !is_subclass_of(
58  $configuration['module'],
59  ModuleInterface::class,
60  true
61  )
62  ) {
64  'The module "' .
65  $identifier .
66  '" defines an invalid module class. Ensure the class exists and implements the "' .
67  ModuleInterface::class .
68  '".',
69  1519490112
70  );
71  }
72  }
73 
74  $orderedModules = GeneralUtility::makeInstance(DependencyOrderingService::class)->orderByDependencies(
75  $modules
76  );
77 
78  $moduleInstances = [];
79  foreach ($orderedModules as $moduleConfiguration) {
80  $module = GeneralUtility::makeInstance($moduleConfiguration['module']);
81  if (
82  $module instanceof ‪ModuleInterface
83  && (
84  ($module instanceof ‪ConfigurableInterface && $module->‪isEnabled())
85  || !($module instanceof ‪ConfigurableInterface)
86  )
87  ) {
88  $moduleInstances[$module->getIdentifier()] = $module;
89  }
90  if ($module instanceof ‪SubmoduleProviderInterface) {
91  $subModuleInstances = $this->‪validateSortAndInitializeModules($moduleConfiguration['submodules'] ?? []);
92  $module->setSubModules($subModuleInstances);
93  }
94  }
95  return $moduleInstances;
96  }
97 }
‪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:24
‪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:46
‪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:42