Community Documentation

hook_uninstall

5 install.php hook_uninstall()
6 install.php hook_uninstall()
7 system.api.php hook_uninstall()
8 system.api.php hook_uninstall()

Remove any information that the module sets.

The information that the module should remove includes:

The module should not remove its entry from the {system} table. 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.

When hook_uninstall() is called, your module will already be disabled, so its .module file will not be automatically included. If you need to call API functions from your .module file in this hook, use drupal_load() to make them available. (Keep this usage to a minimum, though, especially when calling API functions that invoke hooks, or API functions from modules listed as dependencies, since these may not be available or work as expected when the module is disabled.)

See also

hook_install()

hook_schema()

hook_disable()

hook_modules_uninstalled()

Related topics

▾ 23 functions implement hook_uninstall()

aggregator_uninstall in modules/aggregator/aggregator.install
Implements hook_uninstall().
blog_uninstall in modules/blog/blog.install
Implements hook_uninstall().
book_uninstall in modules/book/book.install
Implements hook_uninstall().
comment_uninstall in modules/comment/comment.install
Implements hook_uninstall().
contact_uninstall in modules/contact/contact.install
Implements hook_uninstall().
dashboard_uninstall in modules/dashboard/dashboard.install
Implements hook_uninstall().
dblog_uninstall in modules/dblog/dblog.install
Implements hook_uninstall().
EnableDisableTestCase::assertSuccessfulDisableAndUninstall in modules/system/system.test
Disables and uninstalls a module and asserts that it was done correctly.
forum_uninstall in modules/forum/forum.install
Implements hook_uninstall().
image_uninstall in modules/image/image.install
Implements hook_uninstall().
locale_uninstall in modules/locale/locale.install
Implements hook_uninstall().
menu_uninstall in modules/menu/menu.install
Implements hook_uninstall().
profile_uninstall in modules/profile/profile.install
Implements hook_uninstall().
search_uninstall in modules/search/search.install
Implements hook_uninstall().
shortcut_uninstall in modules/shortcut/shortcut.install
Implements hook_uninstall().
simpletest_uninstall in modules/simpletest/simpletest.install
Implements hook_uninstall().
statistics_uninstall in modules/statistics/statistics.install
Implements hook_uninstall().
syslog_uninstall in modules/syslog/syslog.install
Implements hook_uninstall().
system_modules_uninstall in modules/system/system.admin.inc
Builds a form of currently disabled modules.
taxonomy_uninstall in modules/taxonomy/taxonomy.install
Implements hook_uninstall().
theme_system_modules_uninstall in modules/system/system.admin.inc
Returns HTML for a table of currently disabled modules.
tracker_uninstall in modules/tracker/tracker.install
Implements hook_uninstall().
update_uninstall in modules/update/update.install
Implements hook_uninstall().

File

modules/system/system.api.php, line 3419
Hooks provided by Drupal core and the System module.

Code

<?php
function hook_uninstall() {
  variable_del('upload_file_types');
}
?>

Comments

Do not use API functions supplied by .module files

The code inside a hook_uninstall() implementation should not call any API functions that are provided by any .module file, including its own, unless:

  1. The uninstall code explicitly loads the module file, e.g., by calling drupal_load().
  2. It is absolutely certain that the called API function does not rely on other API functions which may not be available.

See also:

Common Knowledge

This is sort of assumed knowledge but, like hook_install and hook_update_N, this function should live in a .install file.

Login or register to post comments