function hook_modules_installed

Same name and namespace in other branches
  1. 7.x modules/system/system.api.php \hook_modules_installed()
  2. 9 core/lib/Drupal/Core/Extension/module.api.php \hook_modules_installed()
  3. 8.9.x core/lib/Drupal/Core/Extension/module.api.php \hook_modules_installed()
  4. 10 core/lib/Drupal/Core/Extension/module.api.php \hook_modules_installed()

Perform necessary actions after modules are installed.

This function differs from hook_install() in that it gives all other modules a chance to perform actions when a module is installed, whereas hook_install() is only called on the module actually being installed. See \Drupal\Core\Extension\ModuleInstaller::install() for a detailed description of the order in which install hooks are invoked.

This hook should be implemented in a .module file, not in an .install file.

Parameters

string[] $modules: An array of the modules that were installed.

bool $is_syncing: TRUE if the module is being installed as part of a configuration import. In these cases, your hook implementation needs to carefully consider what changes, if any, it should make. For example, it should not make any changes to configuration objects or configuration entities. Those changes should be made earlier and exported so during import there's no need to do them again.

See also

\Drupal\Core\Extension\ModuleInstaller::install()

hook_install()

Related topics

1 string reference to 'hook_modules_installed'
OtherModuleInstalledHooks::modulesInstalled in core/modules/system/tests/modules/respond_install_uninstall_hook_test/src/Hook/OtherModuleInstalledHooks.php
Implements hook_modules_installed().
18 functions implement hook_modules_installed()

Note: the procedural functions in this list are found by pattern matching, so the list may include some functions that are not actually implementations of this hook.

BlockHooks::modulesInstalled in core/modules/block/src/Hook/BlockHooks.php
Implements hook_modules_installed().
ConfigImportTestHooks::modulesInstalled in core/modules/config/tests/config_import_test/src/Hook/ConfigImportTestHooks.php
Implements hook_modules_installed().
config_import_test_modules_installed in core/modules/config/tests/config_import_test/config_import_test.module
Implements hook_modules_installed().
HelpHooks::modulesInstalled in core/modules/help/src/Hook/HelpHooks.php
Implements hook_modules_installed().
JsonapiHooks::modulesInstalled in core/modules/jsonapi/src/Hook/JsonapiHooks.php
Implements hook_modules_installed().

... See full list

2 invocations of hook_modules_installed()
BlockConfigSyncTest::testNoBlocksCreatedDuringConfigSync in core/modules/block/tests/src/Kernel/BlockConfigSyncTest.php
Tests blocks are not created during config sync.
ModuleInstaller::install in core/lib/Drupal/Core/Extension/ModuleInstaller.php

File

core/lib/Drupal/Core/Extension/module.api.php, line 209

Code

function hook_modules_installed($modules, $is_syncing) : void {
  if (in_array('lousy_module', $modules)) {
    \Drupal::state()->set('my_module.lousy_module_compatibility', TRUE);
  }
  if (!$is_syncing) {
    \Drupal::service('my_module.service')->doSomething($modules);
  }
}

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