Disables a given set of modules.
$module_list: An array of module names.
$disable_dependents: If TRUE, dependent modules will automatically be added and disabled in the correct order. This incurs a significant performance cost, so use FALSE if you know $module_list is already complete and in the correct order.
Overrides ModuleHandlerInterface::disable
function disable($module_list, $disable_dependents = TRUE) {
if ($disable_dependents) {
// Get all module data so we can find dependents and sort.
$module_data = system_rebuild_module_data();
// Create an associative array with weights as values.
$module_list = array_flip(array_values($module_list));
$profile = drupal_get_profile();
while (list($module) = each($module_list)) {
if (!isset($module_data[$module]) || !$module_data[$module]->status) {
// This module doesn't exist or is already disabled, skip it.
unset($module_list[$module]);
continue;
}
$module_list[$module] = $module_data[$module]->sort;
// Add dependent modules to the list, with a placeholder weight.
// The new modules will be processed as the while loop continues.
foreach ($module_data[$module]->required_by as $dependent => $dependent_data) {
if (!isset($module_list[$dependent]) && $dependent != $profile) {
$module_list[$dependent] = 0;
}
}
}
// Sort the module list by pre-calculated weights.
asort($module_list);
$module_list = array_keys($module_list);
}
$invoke_modules = array();
$module_config = config('system.module');
$disabled_config = config('system.module.disabled');
foreach ($module_list as $module) {
// Only process modules that are enabled.
// A module is only enabled if it is configured as enabled. Custom or
// overridden module handlers might contain the module already, which means
// that it might be loaded, but not necessarily installed or enabled.
$enabled = $module_config
->get("enabled.{$module}") !== NULL;
if ($enabled) {
module_load_install($module);
module_invoke($module, 'disable');
$disabled_config
->set($module, $module_config
->get($module))
->save();
$module_config
->clear("enabled.{$module}")
->save();
// Update the module handler to remove the module.
// The current ModuleHandler instance is obsolete with the kernel rebuild
// below.
$module_filenames = $this
->getModuleList();
unset($module_filenames[$module]);
$this
->setModuleList($module_filenames);
// Record the fact that it was disabled.
$invoke_modules[] = $module;
watchdog('system', '%module module disabled.', array(
'%module' => $module,
), WATCHDOG_INFO);
}
}
if (!empty($invoke_modules)) {
// @todo Most of the following should happen in above loop already.
// Refresh the system list to exclude the disabled modules.
// @todo Only needed to rebuild theme info.
// @see system_list_reset()
system_list_reset();
entity_info_cache_clear();
// Invoke hook_modules_disabled before disabling modules,
// so we can still call module hooks to get information.
$this
->invokeAll('modules_disabled', array(
$invoke_modules,
));
_system_update_bootstrap_status();
// Update the kernel to exclude the disabled modules.
$enabled = $this
->getModuleList();
drupal_container()
->get('kernel')
->updateModules($enabled, $enabled);
// Update the theme registry to remove the newly-disabled module.
drupal_theme_rebuild();
}
}