I am updating an existing module I have developed. The new version requires a "helper" module that the old version did not (fwiw, specifically "Nodereference Count"). How do I ensure that when people upgrade from the prior version of my module to the new version, they make sure to install the newly required helper module first?

Is there something I should put into hook_update_n function?



You could use hook_requirements(), which should allow you to display an error when the module is installed/updated.

Alternatively, if that doesn't work you can implement hook_init() to run a check for the modules and react accordingly.

Update: I've just run into the same issue myself and here is the code that I have used:

 * Implements hook_init().
function MYMODULE_init() {
  if (!module_exists('ctools')) {
    if (!module_exists('ctools')) {
      drupal_set_message(t('MYMODULE has been disabled as the required !ctools module is not present.', array('!ctools' => l(t('Chaos tool suite'), 'http://drupal.org/project/ctools'))), 'error');

This will try to enable the required module and if it is unable to do so it will display an error message to the user and disable the my module.

  • They will not be able to enable the new dependency through the GUI without disabling your module. – tim.plunkett Mar 19 '11 at 0:16
  • Actually that's not true, if you go to the Modules page and hit submit, any dependencies that are supposed to be enabled will be enabled even though you can't select them. – Decipher Mar 19 '11 at 0:28
  • Decipher, sounds good, will go with hook_requirements. Thanks! – chipcleary Mar 19 '11 at 14:01

Your Answer

