\hook_enable
function
Perform necessary actions after module is enabled.

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.

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