ModuleHandler::buildModuleDependencies

public ModuleHandler::buildModuleDependencies(array $modules)

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 222

Class

ModuleHandler
Class that manages modules in a Drupal installation.

Namespace

Drupal\Core\Extension

Code

public function buildModuleDependencies(array $modules) {
  foreach ($modules as $module) {
    $graph[$module->getName()]['edges'] = array();
    if (isset($module->info['dependencies']) && is_array($module->info['dependencies'])) {
      foreach ($module->info['dependencies'] as $dependency) {
        $dependency_data = static::parseDependency($dependency);
        $graph[$module->getName()]['edges'][$dependency_data['name']] = $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'] : array();
    $modules[$module_name]->requires = isset($data['paths']) ? $data['paths'] : array();
    $modules[$module_name]->sort = $data['weight'];
  }
  return $modules;
}
doc_Drupal
2016-10-29 09:29:14
Comments
Leave a Comment

Please login to continue.