class ModuleInstaller implements ModuleInstallerInterface (View source)

Default implementation of the module installer.

It registers the module in config, installs its own configuration, installs the schema, updates the Drupal kernel and more.

We don't inject dependencies yet, as we would need to reload them after each installation or uninstallation of a module. https://www.drupal.org/project/drupal/issues/2350111 for example tries to solve this dilemma.

Properties

protected ModuleHandlerInterface $moduleHandler

The module handler.

protected DrupalKernelInterface $kernel

The drupal kernel.

protected string $root

The app root.

protected Connection $connection

The database connection.

protected UpdateHookRegistry $updateRegistry

The update registry service.

protected ModuleUninstallValidatorInterface[] $uninstallValidators

The uninstall validators.

Methods

__construct(string $root, ModuleHandlerInterface $module_handler, DrupalKernelInterface $kernel, Connection $connection = NULL, UpdateHookRegistry $update_registry = NULL)

Constructs a new ModuleInstaller instance.

addUninstallValidator(ModuleUninstallValidatorInterface $uninstall_validator)

Adds module a uninstall validator.

bool
install(array $module_list, bool $enable_dependencies = TRUE)

Installs a given list of modules.

bool
uninstall(array $module_list, bool $uninstall_dependents = TRUE)

Uninstalls a given list of modules.

removeCacheBins(string $module)

Helper method for removing all cache bins registered by a given module.

updateKernel(string $module_filenames)

Updates the kernel module list.

string[]
validateUninstall(array $module_list)

Determines whether a list of modules can be uninstalled.

void
installSchema(string $module)

Creates all tables defined in a module's hook_schema().

void
uninstallSchema(string $module)

Removes all tables defined in a module's hook_schema().

Details

__construct(string $root, ModuleHandlerInterface $module_handler, DrupalKernelInterface $kernel, Connection $connection = NULL, UpdateHookRegistry $update_registry = NULL)

Constructs a new ModuleInstaller instance.

Parameters

string $root

The app root.

ModuleHandlerInterface $module_handler

The module handler.

DrupalKernelInterface $kernel

The drupal kernel.

Connection $connection

The database connection.

UpdateHookRegistry $update_registry

(Optional) The update registry service.

See also

DrupalKernel
CoreServiceProvider

addUninstallValidator(ModuleUninstallValidatorInterface $uninstall_validator)

Adds module a uninstall validator.

Parameters

ModuleUninstallValidatorInterface $uninstall_validator

The uninstall validator to add.

bool install(array $module_list, bool $enable_dependencies = TRUE)

Installs a given list of modules.

Order of events:

  • Gather and add module dependencies to $module_list (if applicable).
  • For each module that is being installed:
    • Invoke hook_module_preinstall().
    • Install module schema and update system registries and caches.
    • Invoke hook_install() and add it to the list of installed modules.
  • Invoke hook_modules_installed().

To install test modules add

Parameters

array $module_list

An array of module names.

bool $enable_dependencies

(optional) If TRUE, dependencies will automatically be installed in the correct order. This incurs a significant performance cost, so use FALSE if you know $module_list is already complete.

Return Value

bool

TRUE if the modules were successfully installed.

Exceptions

MissingDependencyException
ExtensionNameLengthException

bool uninstall(array $module_list, bool $uninstall_dependents = TRUE)

Uninstalls a given list of modules.

Parameters

array $module_list

The modules to uninstall.

bool $uninstall_dependents

(optional) If TRUE, dependent modules will automatically be uninstalled in the correct order. This incurs a significant performance cost, so use FALSE if you know $module_list is already complete.

Return Value

bool

FALSE if one or more dependencies are missing, TRUE otherwise.

Exceptions

ModuleUninstallValidatorException

protected removeCacheBins(string $module)

Helper method for removing all cache bins registered by a given module.

Parameters

string $module

The name of the module for which to remove all registered cache bins.

protected updateKernel(string $module_filenames)

Updates the kernel module list.

Parameters

string $module_filenames

The list of installed modules.

string[] validateUninstall(array $module_list)

Determines whether a list of modules can be uninstalled.

Parameters

array $module_list

An array of module names.

Return Value

string[]

An array of reasons the module can not be uninstalled, empty if it can.

protected void installSchema(string $module)

internal  
 

Creates all tables defined in a module's hook_schema().

Parameters

string $module

The module for which the tables will be created.

Return Value

void

protected void uninstallSchema(string $module)

internal  
 

Removes all tables defined in a module's hook_schema().

Parameters

string $module

The module for which the tables will be removed.

Return Value

void