How can I trigger custom code when some other module is being installed/uninstalled?
-
06-02-2021 - |
Question
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?
Solution
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();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange