function ModulesListForm::buildModuleList

Same name and namespace in other branches
  1. 11.x core/modules/system/src/Form/ModulesListForm.php \Drupal\system\Form\ModulesListForm::buildModuleList()
  2. 10 core/modules/system/src/Form/ModulesListForm.php \Drupal\system\Form\ModulesListForm::buildModuleList()
  3. 9 core/modules/system/src/Form/ModulesListForm.php \Drupal\system\Form\ModulesListForm::buildModuleList()
  4. 8.9.x 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 411

Class

ModulesListForm
Provides module installation interface.

Namespace

Drupal\system\Form

Code

protected function buildModuleList(FormStateInterface $form_state) {
  // Build a list of modules to install.
  $modules = [
    'install' => [],
    'dependencies' => [],
    'non_stable' => [],
  ];
  $data = $this->moduleExtensionList
    ->getList();
  // Determine the modules the user explicitly requested: required modules
  // that are not yet installed, plus any that were selected on the form.
  $selected = [];
  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)) {
      $selected[$name] = $module->info['name'];
    }
    elseif (($checkbox = $form_state->getValue([
      'modules',
      $name,
    ], FALSE)) && $checkbox['enable']) {
      $selected[$name] = $data[$name]->info['name'];
    }
  }
  $selected = array_keys($selected);
  // Resolve the full set of modules that will be installed, including any
  // dependencies pulled in automatically. This uses the same resolution as
  // the module installer, so the confirmation form reflects exactly what
  // will be installed. The explicitly selected modules are listed first,
  // followed by the dependencies pulled in automatically, which is the order
  // users expect to see on the confirmation form.
  $resolved = $this->moduleInstaller
    ->getModulesToInstall($selected);
  $ordered = array_merge(array_intersect($selected, $resolved), array_diff($resolved, $selected));
  $modules = $this->classifyByStability($ordered, $modules, $data);
  $modules = $this->groupDependenciesByParent($selected, $modules, $data);
  // 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.