protected function ModulesListForm::buildModuleList in Drupal 8
Same name and namespace in other branches
- 9 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 370
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' => [],
'experimental' => [],
];
$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']) {
$modules['install'][$name] = $data[$name]->info['name'];
// Identify experimental modules.
if ($data[$name]->info['package'] == 'Core (Experimental)') {
$modules['experimental'][$name] = $data[$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)) {
$modules['dependencies'][$module][$dependency] = $data[$dependency]->info['name'];
$modules['install'][$dependency] = $data[$dependency]->info['name'];
// Identify experimental modules.
if ($data[$dependency]->info['package'] == 'Core (Experimental)') {
$modules['experimental'][$dependency] = $data[$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['experimental'][$module]);
foreach (array_keys($data[$module]->required_by) as $dependent) {
unset($modules['install'][$dependent]);
unset($modules['dependencies'][$dependent]);
}
}
}
return $modules;
}