1

I wanted to install few modules when my module is installed. How can this be achieved?

I am creating a module which requires few other modules to be installed. I want to install them when my main module is installed.

I have placed all those module folders inside one main folder, and I want to create an install file to install those modules when this main install file is executed.

1

Just in addition to kiamlaluno's (correct) answer, if you want to get stuck in and do-it-yourself you can use the core module_enable function, perhaps in your module's hook_enable() function:

function MYMODULE_enable() {
  $modules = array('module_1', 'module_2');
  module_enable($modules);
} 

The code is purely for demonstration purposes, I wouldn't actually recommend using it; if you want to make sure certain modules are enabled along with yours, the safest way is to use dependencies[] in your .info file as has already been described.

2
  • I have over 25 modules to be installed and I dont want the user to do this that tiring job. I think your suggestion is a good idea and I am going to try that. – Drupal Developer Mar 30 '12 at 18:36
  • Thank you very much.. your solution suites me better.. :) – Drupal Developer Mar 30 '12 at 18:53
2

If there are modules from which your module depends, your module should declare them as dependencies, in its .info file. Supposing that your module is my_secret_module.module, and it depends from first_module, and second_module, my_secret_module.info should contain the following lines.

// Drupal 5
dependencies = first_module second_module

// Drupal 6, Drupal 7, and next releases
dependencies[] = first_module
dependencies[] = second_module

In this way, your module cannot be enabled of the other modules are not enabled too.

2
  • But I dont want to use dependencies. I want to install the modules myself. I have over 25 dependencies and I dont want the user to install all 25 dependencies individually as it is tiring. – Drupal Developer Mar 30 '12 at 18:34
  • 1
    @DrupalDeveloper Your users won't have to install the modules manually, they just need to enable your module, and all of the dependencies will be installed along with it (after a single confirmation page) – Clive Mar 30 '12 at 18:39

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.