You are here

function hook_uninstall in Drupal 8

Same name and namespace in other branches
  1. 7 modules/system/system.api.php \hook_uninstall()
  2. 9 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.

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, if any, it should make. For example, it should not make any changes to configuration objects or entities.

See also

hook_install()

hook_schema()

hook_modules_uninstalled()

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 312
Hooks related to module and update systems.

Code

function hook_uninstall($is_syncing) {

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