15

There is a lot resource for doing it in Drupal 6, but I didn't find a solution for Drupal 7.

How can I install and enable selected modules?

25

There's just one step, using module_enable():

$modules = array('module1', 'module2'); // Array of module names
$enable_dependencies = TRUE; // Whether or not to enable dependant modules

module_enable($modules, $enable_dependencies);
  • Does this enable the modules in the same order as they are in the array? – Brent Connor May 16 '18 at 15:25
  • No @BrentConnor, a dependency map is computed and they're installed in whatever order make sense – Clive May 16 '18 at 15:35
7

Here is how you would do it within an update (visiting update.php or drush updb)

function mymodule_update_7101() {

    $modules = array('module1', 'module2'); // Array of module names
    $enable_dependencies = TRUE; // Whether or not to enable dependant modules

    module_enable($modules, $enable_dependencies);

}
  • That was the answer for me. I need to script drush updb -y in my deployment process (Jenkins). – Guillaume Bois Apr 6 '15 at 15:30
1

In Drupal 7 there is no more drupal_install_modules(), therefore if you want to force the module installation process programmatically (if it's already enabled), you can use:

module_invoke('module_name', 'install');

To enable, it's simply:

module_enable(array('module_name'));

Or using drush as part of the deployment process:

drush -y en module_name

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.