ModulesListForm::buildModuleList

protected ModulesListForm::buildModuleList(FormStateInterface $form_state)

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.

File

core/modules/system/src/Form/ModulesListForm.php, line 359

Class

ModulesListForm
Provides module installation interface.

Namespace

Drupal\system\Form

Code

protected function buildModuleList(FormStateInterface $form_state) {
  $packages = $form_state->getValue('modules');

  // Build a list of modules to install.
  $modules = array(
    'install' => array(),
    'dependencies' => array(),
    'experimental' => [],
  );

  // Required modules have to be installed.
  // @todo This should really not be handled here.
  $data = system_rebuild_module_data();
  foreach ($data as $name => $module) {
    if (!empty($module->required) && !$this->moduleHandler->moduleExists($name)) {
      $modules['install'][$name] = $module->info['name'];
    }
  }

  // First, build a list of all modules that were selected.
  foreach ($packages as $package => $items) {
    foreach ($items as $name => $checkbox) {
      if ($checkbox['enable'] && !$this->moduleHandler->moduleExists($name)) {
        $modules['install'][$name] = $data[$name]->info['name'];
        // Identify experimental modules.
        if ($package == 'Core (Experimental)') {
          $modules['experimental'][$name] = $data[$name]->info['name'];
        }
      }
    }
  }

  // Add all dependencies to a list.
  while (list($module) = each($modules['install'])) {
    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]);
      foreach (array_keys($data[$module]->required_by) as $dependent) {
        unset($modules['install'][$dependent]);
        unset($modules['dependencies'][$dependent]);
      }
    }
  }

  return $modules;
}
doc_Drupal
2016-10-29 09:29:37
Comments
Leave a Comment

Please login to continue.