function ModulesListForm::buildModuleList
Same name in other branches
- 9 core/modules/system/src/Form/ModulesListForm.php \Drupal\system\Form\ModulesListForm::buildModuleList()
- 8.9.x core/modules/system/src/Form/ModulesListForm.php \Drupal\system\Form\ModulesListForm::buildModuleList()
- 10 core/modules/system/src/Form/ModulesListForm.php \Drupal\system\Form\ModulesListForm::buildModuleList()
Helper function for building a list of modules to install.
Parameters
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array An array of modules to install and their dependencies.
1 call to ModulesListForm::buildModuleList()
- ModulesListForm::submitForm in core/
modules/ system/ src/ Form/ ModulesListForm.php - Form submission handler.
File
-
core/
modules/ system/ src/ Form/ ModulesListForm.php, line 412
Class
- ModulesListForm
- Provides module installation interface.
Namespace
Drupal\system\FormCode
protected function buildModuleList(FormStateInterface $form_state) {
// Build a list of modules to install.
$modules = [
'install' => [],
'dependencies' => [],
'non_stable' => [],
];
$data = $this->moduleExtensionList
->getList();
foreach ($data as $name => $module) {
// If the module is installed there is nothing to do.
if ($this->moduleHandler
->moduleExists($name)) {
continue;
}
// Required modules have to be installed.
if (!empty($module->required)) {
$modules['install'][$name] = $module->info['name'];
}
elseif (($checkbox = $form_state->getValue([
'modules',
$name,
], FALSE)) && $checkbox['enable']) {
$info = $data[$name]->info;
$modules['install'][$name] = $info['name'];
// Identify non-stable modules.
$lifecycle = $info[ExtensionLifecycle::LIFECYCLE_IDENTIFIER];
if ($lifecycle !== ExtensionLifecycle::STABLE) {
$modules['non_stable'][$name] = $info['name'];
}
}
}
// Add all dependencies to a list.
foreach ($modules['install'] as $module => $value) {
foreach (array_keys($data[$module]->requires) as $dependency) {
if (!isset($modules['install'][$dependency]) && !$this->moduleHandler
->moduleExists($dependency)) {
$dependency_info = $data[$dependency]->info;
$modules['dependencies'][$module][$dependency] = $dependency_info['name'];
$modules['install'][$dependency] = $dependency_info['name'];
// Identify non-stable modules.
$lifecycle = $dependency_info[ExtensionLifecycle::LIFECYCLE_IDENTIFIER];
if ($lifecycle !== ExtensionLifecycle::STABLE) {
$modules['non_stable'][$dependency] = $dependency_info['name'];
}
}
}
}
// Make sure the install API is available.
include_once DRUPAL_ROOT . '/core/includes/install.inc';
// Invoke hook_requirements('install'). If failures are detected, make
// sure the dependent modules aren't installed either.
foreach (array_keys($modules['install']) as $module) {
if (!drupal_check_module($module)) {
unset($modules['install'][$module]);
unset($modules['non_stable'][$module]);
foreach (array_keys($data[$module]->required_by) as $dependent) {
unset($modules['install'][$dependent]);
unset($modules['dependencies'][$dependent]);
}
}
}
return $modules;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.