By mradcliffe on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
11.5.x
Introduced in version:
11.5.0
Issue links:
Description:
Two methods have been added so that callers can find out what an install would install prior to installing it. Class implementations for these methods must now implement the new method. There is no change necessary for code that extends the core installer classes.
\Drupal\Core\Extension\ModuleInstallerInterface::getModulesToInstall(array $module_list, bool $enable_dependencies = TRUE): array\Drupal\Core\Extension\ThemeInstallerInterface::getThemesToInstall(array $theme_list, bool $install_dependencies = TRUE): array
Each returns the machine names of the extensions that are not yet installed, including resolved dependencies, in the order to install them. Already installed extensions are omitted. ModuleInstaller::install() and ThemeInstaller::install() now delegate to these methods.
The Drupal CLI ex:install command and Module Administration form use this to list exactly what will be installed, including dependencies.
Example
/** @var \Drupal\Core\Extension\ModuleInstaller $installer */
$installer = \Drupal::service('module_installer');
// Returns an indexed array in order of dependency resolution: autowire_test, console_test.
$modules = $installer->getModulesToInstall(['console_test']);
// Installs autowire_test and then console_test.
$installer->install($modules);
Impacts:
Module developers