You are here

function system_modules_submit in Drupal 5

Same name and namespace in other branches
  1. 4 modules/system.module \system_modules_submit()
  2. 6 modules/system/system.admin.inc \system_modules_submit()
  3. 7 modules/system/system.admin.inc \system_modules_submit()

Submit callback; handles modules form submission.

File

modules/system/system.module, line 1456
Configuration system that lets administrators modify the workings of the site.

Code

function system_modules_submit($form_id, $form_values) {
  include_once './includes/install.inc';
  $new_modules = array();

  // Merge in disabled active modules since they should be enabled.
  // They don't appear because disabled checkboxes are not submitted
  // by browsers.
  $form_values['status'] = array_merge($form_values['status'], $form_values['disabled_modules']);

  // Check values for dependency that we can't install.
  if ($dependencies = system_module_build_dependencies($form_values['validation_modules'], $form_values)) {

    // These are the modules that depend on existing modules.
    foreach (array_keys($dependencies) as $name) {
      $form_values['status'][$name] = 0;
    }
  }
  $enable_modules = array();
  $disable_modules = array();
  foreach ($form_values['status'] as $key => $choice) {
    if ($choice) {
      if (drupal_get_installed_schema_version($key) == SCHEMA_UNINSTALLED) {
        $new_modules[] = $key;
      }
      else {
        $enable_modules[] = $key;
      }
    }
    else {
      $disable_modules[] = $key;
    }
  }
  $old_module_list = module_list();
  if (!empty($enable_modules)) {
    module_enable($enable_modules);
  }
  if (!empty($disable_modules)) {
    module_disable($disable_modules);
  }

  // Install new modules.
  foreach ($new_modules as $key => $module) {
    if (!drupal_check_module($module)) {
      unset($new_modules[$key]);
    }
  }
  drupal_install_modules($new_modules);
  $current_module_list = module_list(TRUE, FALSE);
  if (is_array($form_values['throttle'])) {
    foreach ($form_values['throttle'] as $key => $choice) {
      db_query("UPDATE {system} SET throttle = %d WHERE type = 'module' and name = '%s'", $choice ? 1 : 0, $key);
    }
  }
  if ($old_module_list != $current_module_list) {
    menu_rebuild();
    node_types_rebuild();
    drupal_set_message(t('The configuration options have been saved.'));
  }

  // If there where unmet dependencies and they haven't confirmed don't redirect.
  if ($dependencies && !isset($form_values['confirm'])) {
    return FALSE;
  }
  drupal_clear_css_cache();
  return 'admin/build/modules';
}