7.x system.api.php hook_modules_enabled($modules)

Perform necessary actions after modules are enabled.

This function differs from hook_enable() in that it gives all other modules a chance to perform actions when modules are enabled, whereas hook_enable() is only called on the module actually being enabled. See module_enable() for a detailed description of the order in which install and enable hooks are invoked.


$modules: An array of the modules that were enabled.

See also




Related topics

7 functions implement hook_modules_enabled()

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

comment_modules_enabled in modules/comment/comment.install
Implements hook_modules_enabled().
field_modules_enabled in modules/field/field.module
Implements hook_modules_enabled().
filter_modules_enabled in modules/filter/filter.module
Implements hook_modules_enabled().
locale_modules_enabled in modules/locale/locale.module
Implements hook_modules_enabled().
module_test_modules_enabled in modules/simpletest/tests/module_test.module
Implements hook_modules_enabled().

... See full list

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


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


function hook_modules_enabled($modules) {
  if (in_array('lousy_module', $modules)) {
    drupal_set_message(t('mymodule is not compatible with lousy_module'), 'error');


jyee’s picture

hook_modules_enabled() does not run during Drupal site installation. In other words, you cannot rely on this hook for any module enabled by an install profile.

bojanz’s picture

This is not true, at least for D7.
hook_modules_enabled() runs normally.

Sylvain Lecoy’s picture

Drupal trick

Put this in your install file so the hook runs once only when your module is installed.

This has the following benefits:

  • Hooks definitions has been parsed, think of image_styles(), or date_format_types() for instances.
  • Sometimes you need these hooks definitions parsed and loaded such as menu items to write installation materials depending on these definitions.
pfrenssen’s picture

It is no longer possible to disable and enable modules in Drupal 8, so use hook_modules_installed() instead.

See Modules cannot be in a disabled state anymore, only installed and uninstalled.