1

I am using a third-party module. Whenever it is installed or un-installed, I want to programmatically create/delete some menus.

How can I detect that a module is installed or un-installed?

2

You can use hook_modules_installed() to react to modules being installed, e.g.

function hook_modules_installed($modules) {
  if (in_array('lousy_module', $modules)) {
    variable_set('lousy_module_conflicting_variable', FALSE);
  }
}

and hook_modules_uninstalled() to react to the opposite, e.g.

function hook_modules_uninstalled($modules) {
  foreach ($modules as $module) {
    db_delete('mymodule_table')
      ->condition('module', $module)
      ->execute();
  }
  mymodule_cache_rebuild();
}
1
  • This is working, and in my case, I need to use hook_modules_disabled() and hook_modules_enabled(). Yes, Thanks for pointing me in right direction. – Saba Feb 1 '19 at 10:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.