function RecipeRunner::installModules

Same name and namespace in other branches
  1. main core/lib/Drupal/Core/Recipe/RecipeRunner.php \Drupal\Core\Recipe\RecipeRunner::installModules()

Installs modules for a recipe.

Parameters

string[] $modules: The names of the modules to install. It is up to the caller to ensure that the number of modules to install conforms to the 'core.multi_module_install_batch_size' setting.

\Drupal\Core\Config\StorageInterface|\Drupal\Core\Recipe\Recipe $recipeConfigStorage: The recipe or recipe's config storage.

array<mixed>|null $context: The batch context if called by a batch.

2 calls to RecipeRunner::installModules()
RecipeRunner::installModule in core/lib/Drupal/Core/Recipe/RecipeRunner.php
Installs a module for a recipe.
RecipeRunner::processInstall in core/lib/Drupal/Core/Recipe/RecipeRunner.php
Installs the extensions.

File

core/lib/Drupal/Core/Recipe/RecipeRunner.php, line 294

Class

RecipeRunner
Applies a recipe.

Namespace

Drupal\Core\Recipe

Code

public static function installModules(array $modules, StorageInterface|Recipe $recipeConfigStorage, ?array &$context = NULL) : void {
  if (empty($modules)) {
    throw new \InvalidArgumentException('No modules provided.');
  }
  if ($recipeConfigStorage instanceof Recipe) {
    $recipeConfigStorage = $recipeConfigStorage->config
      ->getConfigStorage();
  }
  // Disable configuration entity install but use the config directories from
  // the modules.
  \Drupal::service('config.installer')->setSyncing(TRUE);
  // Allow the recipe to override simple configuration from the modules.
  $storage = new RecipeOverrideConfigStorage($recipeConfigStorage, RecipeMultipleModulesConfigStorage::createFromModuleList($modules, \Drupal::service('extension.list.module')));
  \Drupal::service('config.installer')->setSourceStorage($storage);
  \Drupal::service('module_installer')->install($modules);
  \Drupal::service('config.installer')->setSyncing(FALSE);
  $module_list = \Drupal::service('extension.list.module');
  $module_names = array_map($module_list->getName(...), $modules);
  $context['message'] = new PluralTranslatableMarkup(count($modules), 'Installed %modules module.', 'Installed @count modules: %modules.', [
    '%modules' => implode(', ', $module_names),
  ]);
  if (isset($context['results']['module'])) {
    $context['results']['module'] = array_merge($context['results']['module'], $modules);
  }
  else {
    $context['results']['module'] = $modules;
  }
}

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