function RecipeRunner::installModule

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

Installs a module for a recipe.

Parameters

string $module: The name of the module to install.

\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.

1 call to RecipeRunner::installModule()
RecipeRunner::processInstall in core/lib/Drupal/Core/Recipe/RecipeRunner.php
Installs the extensions.

File

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

Class

RecipeRunner
Applies a recipe.

Namespace

Drupal\Core\Recipe

Code

public static function installModule(string $module, StorageInterface|Recipe $recipeConfigStorage, ?array &$context = NULL) : void {
  if ($recipeConfigStorage instanceof Recipe) {
    $recipeConfigStorage = $recipeConfigStorage->config
      ->getConfigStorage();
  }
  // Disable configuration entity install but use the config directory from
  // the module.
  \Drupal::service('config.installer')->setSyncing(TRUE);
  $default_install_path = \Drupal::service('extension.list.module')->get($module)
    ->getPath() . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY;
  // Allow the recipe to override simple configuration from the module.
  $storage = new RecipeOverrideConfigStorage($recipeConfigStorage, new FileStorage($default_install_path, StorageInterface::DEFAULT_COLLECTION));
  \Drupal::service('config.installer')->setSourceStorage($storage);
  \Drupal::service('module_installer')->install([
    $module,
  ]);
  \Drupal::service('config.installer')->setSyncing(FALSE);
  $context['message'] = t('Installed %module module.', [
    '%module' => \Drupal::service('extension.list.module')->getName($module),
  ]);
  $context['results']['module'][] = $module;
}

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