Wednesday, December 21, 2011

What is the use of hook_enable?

To show a message after a module gets installed we can use the hook_enable.

For example:

If a module requires a necessary permission to access that module, as soon as the admin installed that module in the drupal admin, we need to show them a message to enable the necessary access permission to access this module at the top.

/**
 * Implementation of hook_enable().
 */
function module_name_enable() {
  drupal_set_message(t('Your module enabled. Don\'t forget to <a href="@link">set permissions</a>.', array('@link' => url('admin/user/permissions', array('fragment' => 'your_custom_module')))));
}