public function ModuleHandler::buildModuleDependencies in Drupal 8
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/Extension/ModuleHandler.php \Drupal\Core\Extension\ModuleHandler::buildModuleDependencies()
- 10 core/lib/Drupal/Core/Extension/ModuleHandler.php \Drupal\Core\Extension\ModuleHandler::buildModuleDependencies()
Determines which modules require and are required by each module.
Parameters
array $modules: An array of module objects keyed by module name. Each object contains information discovered during a Drupal\Core\Extension\ExtensionDiscovery scan.
Return value
The same array with the new keys for each module:
- requires: An array with the keys being the modules that this module requires.
- required_by: An array with the keys being the modules that will not work without this module.
Overrides ModuleHandlerInterface::buildModuleDependencies
See also
\Drupal\Core\Extension\ExtensionDiscovery
File
- core/
lib/ Drupal/ Core/ Extension/ ModuleHandler.php, line 223
Class
- ModuleHandler
- Class that manages modules in a Drupal installation.
Namespace
Drupal\Core\ExtensionCode
public function buildModuleDependencies(array $modules) {
foreach ($modules as $module) {
$graph[$module
->getName()]['edges'] = [];
if (isset($module->info['dependencies']) && is_array($module->info['dependencies'])) {
foreach ($module->info['dependencies'] as $dependency) {
$dependency_data = Dependency::createFromString($dependency);
$graph[$module
->getName()]['edges'][$dependency_data
->getName()] = $dependency_data;
}
}
}
$graph_object = new Graph($graph);
$graph = $graph_object
->searchAndSort();
foreach ($graph as $module_name => $data) {
$modules[$module_name]->required_by = isset($data['reverse_paths']) ? $data['reverse_paths'] : [];
$modules[$module_name]->requires = isset($data['paths']) ? $data['paths'] : [];
$modules[$module_name]->sort = $data['weight'];
}
return $modules;
}