function hook_uninstall

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

Remove any information that the module sets.

The information that the module should remove includes:

  • state that the module has set using \Drupal::state()
  • modifications to existing tables

The module should not remove its entry from the module configuration. Database tables defined by hook_schema() will be removed automatically.

The uninstall hook must be implemented in the module's .install file. It will fire when the module gets uninstalled but before the module's database tables are removed, allowing your module to query its own tables during this routine.

Adding custom logic to hook_uninstall implementations to check for criteria before uninstalling, does not take advantage of the module uninstall page UI. Instead, use \Drupal\Core\Extension\ModuleUninstallValidatorInterface.

Parameters

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_install()

hook_schema()

hook_modules_uninstalled()

\Drupal\Core\Extension\ModuleUninstallValidatorInterface

Related topics

15 functions implement hook_uninstall()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

book_uninstall in core/modules/book/book.install
Implements hook_uninstall().
comment_uninstall in core/modules/comment/comment.install
Implements hook_uninstall().
demo_umami_content_uninstall in core/profiles/demo_umami/modules/demo_umami_content/demo_umami_content.install
Implements hook_uninstall().
field_layout_uninstall in core/modules/field_layout/field_layout.install
Implements hook_uninstall().
forum_uninstall in core/modules/forum/forum.install
Implements hook_uninstall().

... See full list

1 invocation of hook_uninstall()
ModuleInstaller::uninstall in core/lib/Drupal/Core/Extension/ModuleInstaller.php
Uninstalls a given list of modules.

File

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

Code

function hook_uninstall($is_syncing) {
    // Delete remaining general module variables.
    \Drupal::state()->delete('mymodule.foo');
}

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