function install_profile_modules

Same name in other branches
  1. 7.x includes/install.core.inc \install_profile_modules()
  2. 9 core/includes/install.core.inc \install_profile_modules()
  3. 8.9.x core/includes/install.core.inc \install_profile_modules()
  4. 10 core/includes/install.core.inc \install_profile_modules()

Installs required modules via a batch process.

Parameters

array $install_state: An array of information about the current installation state.

Return value

array The batch definition.

1 string reference to 'install_profile_modules'
install_tasks in core/includes/install.core.inc
Returns a list of all tasks the installer currently knows about.

File

core/includes/install.core.inc, line 1578

Code

function install_profile_modules(&$install_state) {
    // We need to manually trigger the installation of core-provided entity types,
    // as those will not be handled by the module installer.
    install_core_entity_type_definitions();
    $modules = $install_state['profile_info']['install'];
    $files = \Drupal::service('extension.list.module')->getList();
    // Always install required modules first. Respect the dependencies between
    // the modules.
    $required = [];
    $non_required = [];
    // Add modules that other modules depend on.
    foreach ($modules as $module) {
        if ($files[$module]->requires) {
            $modules = array_merge($modules, array_keys($files[$module]->requires));
        }
    }
    // The System module has already been installed by install_base_system().
    $modules = array_diff(array_unique($modules), [
        'system',
    ]);
    foreach ($modules as $module) {
        if (!empty($files[$module]->info['required'])) {
            $required[$module] = $files[$module]->sort;
        }
        else {
            $non_required[$module] = $files[$module]->sort;
        }
    }
    arsort($required);
    arsort($non_required);
    $batch_builder = new BatchBuilder();
    // Put modules into groups of up to the maximum batch size, or until a module
    // states that it needs a container rebuild before and after install.
    $index = 0;
    $module_groups = [];
    foreach (array_keys($required + $non_required) as $module) {
        // If the container needs to be rebuilt, ensure this happens both before and
        // after the module is installed.
        $container_rebuild_required = !empty($files[$module]->info['container_rebuild_required']);
        if ($container_rebuild_required && !empty($module_groups[$index])) {
            $index++;
        }
        $module_groups[$index][] = $module;
        if (count($module_groups[$index]) === Settings::get('core.multi_module_install_batch_size', 20)) {
            $index++;
        }
        elseif ($container_rebuild_required) {
            $index++;
        }
    }
    foreach ($module_groups as $module_group) {
        $names = [];
        foreach ($module_group as $module) {
            $names[] = $files[$module]->info['name'];
        }
        $batch_builder->addOperation('_install_module_batch', [
            $module_group,
            $names,
        ]);
    }
    $batch_builder->setTitle(t('Installing @drupal', [
        '@drupal' => drupal_install_profile_distribution_name(),
    ]))
        ->setErrorMessage(t('The installation has encountered an error.'));
    return $batch_builder->toArray();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.