function hook_modules_uninstalled

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

Perform necessary actions after modules are uninstalled.

This function differs from hook_uninstall() in that it gives all other modules a chance to perform actions when a module is uninstalled, whereas hook_uninstall() is only called on the module actually being uninstalled.

It is recommended that you implement this hook if your module stores data that may have been set by other modules.

Parameters

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

bool $is_syncing: TRUE if the module is being uninstalled as part of a configuration import. In these cases, your hook implementation needs to carefully consider what 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

hook_uninstall()

Related topics

1 string reference to 'hook_modules_uninstalled'
OtherModuleUninstalledHooks::modulesUninstall in core/modules/system/tests/modules/respond_install_uninstall_hook_test/src/Hook/OtherModuleUninstalledHooks.php
Implements hook_modules_uninstalled().
9 functions implement hook_modules_uninstalled()

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.

HelpHooks::modulesUninstalled in core/modules/help/src/Hook/HelpHooks.php
Implements hook_modules_uninstalled().
LanguageHooks::modulesInstalled in core/modules/language/src/Hook/LanguageHooks.php
Implements hook_modules_installed().
module_test_modules_uninstalled in core/modules/system/tests/modules/module_test/module_test.module
Implements hook_modules_uninstalled().
NodeHooks1::modulesUninstalled in core/modules/node/src/Hook/NodeHooks1.php
Implements hook_modules_uninstalled().
OtherModuleUninstalledHooks::modulesUninstall in core/modules/system/tests/modules/respond_install_uninstall_hook_test/src/Hook/OtherModuleUninstalledHooks.php
Implements hook_modules_uninstalled().

... See full list

1 invocation of hook_modules_uninstalled()
ModuleInstaller::uninstall in core/lib/Drupal/Core/Extension/ModuleInstaller.php

File

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

Code

function hook_modules_uninstalled($modules, $is_syncing) : void {
  if (in_array('lousy_module', $modules)) {
    \Drupal::state()->delete('my_module.lousy_module_compatibility');
  }
  my_module_cache_rebuild();
  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.