5.x install.php hook_enable()
6.x install.php hook_enable()
7.x system.api.php hook_enable()

Perform necessary actions after module is enabled.

The hook is called every time the module is enabled. It should be implemented in the module's .install file. The implementation can rely on the .module file being loaded.

See also

module_enable()

hook_install()

hook_modules_enabled()

Related topics

11 functions implement hook_enable()

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

comment_enable in modules/comment/comment.install
Implements hook_enable().
dashboard_enable in modules/dashboard/dashboard.install
Implements hook_enable().
forum_enable in modules/forum/forum.install
Implements hook_enable().
menu_enable in modules/menu/menu.module
Implements hook_enable().
module_enable in includes/module.inc
Enables or installs a given list of modules.

... See full list

1 invocation of hook_enable()
module_enable in includes/module.inc
Enables or installs a given list of modules.

File

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

Code

function hook_enable() {
  mymodule_cache_rebuild();
}

Comments

bhosmer’s picture

An example of using hook_enable:

/**
  * Implement hook_enable()
  */
function yourmodulename_enable() {
drupal_set_message($message = t('The yourmodulename  module was successfully enabled.'), $type = 'status');
}
crobicha’s picture

Is it possible to use this hook to apply a bug-fix patch to another module?

ex. Calling php's exec("git apply ") ?

afinnarn’s picture

You could just have two versions of the module and enable the patched version while disabling the un-patched version from another module's hook_enable function. That approach seems much simpler than triggering git commands.

Another approach to look at is https://www.drupal.org/project/patch_manager

dman’s picture

Drupal8, hook_enable has gone away.

hook_enable() functionality should be moved to hook_install()