How can I trigger custom code when some other module is being installed/uninstalled?

drupal.stackexchange https://drupal.stackexchange.com/questions/275987

  •  06-02-2021
  •  | 
  •  

Pergunta

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?

Foi útil?

Solução

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();
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a drupal.stackexchange
scroll top