Community Documentation

module_disable

5 module.inc module_disable($module_list)
6 module.inc module_disable($module_list)
7 module.inc module_disable($module_list, $disable_dependents = TRUE)
8 module.inc module_disable($module_list, $disable_dependents = TRUE)

Disable a given set of modules.

Parameters

$module_list: An array of module names.

▾ 2 functions call module_disable()

system_modules_submit in modules/system/system.admin.inc
Submit callback; handles modules form submission.
system_update_6018 in modules/system/system.install
Add HTML corrector to HTML formats or replace the old module if it was in use.

File

includes/module.inc, line 349
API for loading and interacting with Drupal modules.

Code

<?php
function module_disable($module_list) {
  $invoke_modules = array();
  foreach ($module_list as $module) {
    if (module_exists($module)) {
      // Check if node_access table needs rebuilding.
      if (!node_access_needs_rebuild() && module_hook($module, 'node_grants')) {
        node_access_needs_rebuild(TRUE);
      }

      module_load_install($module);
      module_invoke($module, 'disable');
      db_query("UPDATE {system} SET status = %d, throttle = %d WHERE type = '%s' AND name = '%s'", 0, 0, 'module', $module);
      $invoke_modules[] = $module;
    }
  }

  if (!empty($invoke_modules)) {
    // Refresh the module list to exclude the disabled modules.
    module_list(TRUE, FALSE);
    // Force to regenerate the stored list of hook implementations.
    module_implements('', FALSE, TRUE);
  }

  // If there remains no more node_access module, rebuilding will be
  // straightforward, we can do it right now.
  if (node_access_needs_rebuild() && count(module_implements('node_grants')) == 0) {
    node_access_rebuild();
  }
}
?>

Comments

You may be using this

You may be using this function in a hook_update_N() implementation to disable a module which was required by a previous version of your codebase. If that's the case, you may also wish to call drupal_uninstall_module() to completely uninstall the module. This function calls the module's hook_uninstall() implementation, which should delete all its data from the database and make it as if the module was never installed in the first place (clean databases are happy databases). Note that drupal_uninstall_module() doesn't want you to pass it an array, however. (And also make sure that the module you're disabling isn't required by any other module before you do this!)

<?php
/**
* Uninstall unneeded module.
*/
function mymodule_update_6102() {
 
module_disable(array('unneeded_module'));
 
drupal_uninstall_module('unneeded_module');
 
// It's expected that hook_update_N() implementations return an array
 
return array();
}
?>

Login or register to post comments