system_modules_submit($form, &$form_state)Submit callback; handles modules form submission.
modules/system/system.admin.inc, line 1110
<?php
function system_modules_submit($form, &$form_state) {
include_once DRUPAL_ROOT . '/includes/install.inc';
$modules = array();
// If we're not coming from the confirmation form, build the list of modules.
if (empty($form_state['storage'])) {
foreach ($form_state['values']['modules'] as $group_name => $group) {
foreach ($group as $module => $enabled) {
$modules[$module] = array('group' => $group_name, 'enabled' => $enabled['enable']);
}
}
}
else {
// If we are coming from the confirmation form, fetch
// the modules out of $form_state.
$modules = $form_state['storage']['modules'];
}
// Get a list of all modules, it will be used to find which module requires
// which.
$files = system_rebuild_module_data();
// The modules to be enabled.
$modules_to_be_enabled = array();
// The modules to be disabled.
$disable_modules = array();
// The modules to be installed.
$new_modules = array();
// Modules that need to be switched on because other modules require them.
$more_modules = array();
$missing_modules = array();
// Go through each module, finding out if we should enable, install, or
// disable it. Also, we find out if there are modules it requires that are
// not enabled.
foreach ($modules as $name => $module) {
// If it's enabled, find out whether to just
// enable it, or install it.
if ($module['enabled']) {
if (drupal_get_installed_schema_version($name) == SCHEMA_UNINSTALLED) {
$new_modules[$name] = $name;
}
elseif (!module_exists($name)) {
$modules_to_be_enabled[$name] = $name;
}
// If we're not coming from a confirmation form, search for modules the
// new ones require and see whether there are any that additionally
// need to be switched on.
if (empty($form_state['storage'])) {
foreach ($form['modules'][$module['group']][$name]['#requires'] as $requires => $v) {
if (!isset($files[$requires])) {
// The required module is missing, mark this module as disabled.
$missing_modules[$requires]['depends'][] = $name;
$modules[$name]['enabled'] = FALSE;
}
else {
if (!$modules[$requires]['enabled']) {
if (!isset($more_modules[$name])) {
$more_modules[$name]['name'] = $files[$name]->info['name'];
}
$more_modules[$name]['requires'][$requires] = $files[$requires]->info['name'];
}
$modules[$requires] = array('group' => $files[$requires]->info['package'], 'enabled' => TRUE);
}
}
}
}
}
// A second loop is necessary, otherwise the modules set to be enabled in the
// previous loop would not be found.
foreach ($modules as $name => $module) {
if (module_exists($name) && !$module['enabled']) {
$disable_modules[$name] = $name;
}
}
if ($more_modules || $missing_modules) {
// If we need to switch on more modules because other modules require
// them and they haven't confirmed, don't process the submission yet. Store
// the form submission data needed later.
$form_state['storage'] = array(
'more_modules' => $more_modules,
'missing_modules' => $missing_modules,
'modules' => $modules
);
$form_state['rebuild'] = TRUE;
return;
}
$old_module_list = module_list();
// Enable the modules needing enabling.
if (!empty($modules_to_be_enabled)) {
$sort = array();
foreach ($modules_to_be_enabled as $module) {
$sort[$module] = $files[$module]->sort;
}
array_multisort($sort, SORT_DESC, $modules_to_be_enabled);
module_enable($modules_to_be_enabled, FALSE);
}
// Disable the modules that need disabling.
if (!empty($disable_modules)) {
$sort = array();
foreach ($disable_modules as $module) {
$sort[$module] = $files[$module]->sort;
}
array_multisort($sort, SORT_ASC, $disable_modules);
module_disable($disable_modules, FALSE);
}
// Install new modules.
if (!empty($new_modules)) {
$sort = array();
foreach ($new_modules as $key => $module) {
if (!drupal_check_module($module)) {
unset($new_modules[$key]);
}
$sort[$module] = $files[$module]->sort;
}
array_multisort($sort, SORT_DESC, $new_modules);
module_enable($new_modules, FALSE);
}
$current_module_list = module_list(TRUE);
if ($old_module_list != $current_module_list) {
drupal_set_message(t('The configuration options have been saved.'));
}
// Clear all caches.
registry_rebuild();
drupal_theme_rebuild();
node_types_rebuild();
menu_rebuild();
cache_clear_all('schema', 'cache');
entity_info_cache_clear();
drupal_clear_css_cache();
drupal_clear_js_cache();
$form_state['redirect'] = 'admin/modules';
// Notify locale module about module changes, so translations can be
// imported. This might start a batch, and only return to the redirect
// path after that.
module_invoke('locale', 'system_update', $new_modules);
// Synchronize to catch any actions that were added or removed.
actions_synchronize();
return;
}
?>