You are here

function system_modules in Drupal 6

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

Menu callback; provides module enable/disable interface.

Modules can be enabled or disabled and set for throttling if the throttle module is enabled. The list of modules gets populated by module.info files, which contain each module's name, description and dependencies.

Dependency checking is performed to ensure that a module cannot be enabled if the module has disabled dependencies and also to ensure that the module cannot be disabled if the module has enabled dependents.

Parameters

$form_state: An associative array containing the current state of the form.

Return value

The form array.

See also

drupal_parse_info_file for information on module.info descriptors.

theme_system_modules()

system_modules_submit()

Related topics

2 string references to 'system_modules'
system_menu in modules/system/system.module
Implementation of hook_menu().
update_form_alter in modules/update/update.module
Implementation of hook_form_alter().

File

modules/system/system.admin.inc, line 636
Admin page callbacks for the system module.

Code

function system_modules($form_state = array()) {

  // Get current list of modules.
  $files = module_rebuild_cache();

  // Remove hidden modules from display list.
  $visible_files = $files;
  foreach ($visible_files as $filename => $file) {
    if (!empty($file->info['hidden'])) {
      unset($visible_files[$filename]);
    }
  }
  uasort($visible_files, 'system_sort_modules_by_info_name');
  if (!empty($form_state['storage'])) {
    return system_modules_confirm_form($visible_files, $form_state['storage']);
  }
  $dependencies = array();

  // Store module list for validation callback.
  $form['validation_modules'] = array(
    '#type' => 'value',
    '#value' => $visible_files,
  );

  // Create storage for disabled modules as browser will disable checkboxes.
  $form['disabled_modules'] = array(
    '#type' => 'value',
    '#value' => array(),
  );

  // Traverse the files, checking for compatibility
  $incompatible_core = array();
  $incompatible_php = array();
  foreach ($visible_files as $filename => $file) {

    // Ensure this module is compatible with this version of core.
    if (!isset($file->info['core']) || $file->info['core'] != DRUPAL_CORE_COMPATIBILITY) {
      $incompatible_core[$file->name] = $file->name;
    }

    // Ensure this module is compatible with the currently installed version of PHP.
    if (version_compare(phpversion(), $file->info['php']) < 0) {
      $incompatible_php[$file->name] = $file->info['php'];
    }
  }

  // Array for disabling checkboxes in callback system_module_disable.
  $disabled = array();
  $throttle = array();

  // Traverse the files retrieved and build the form.
  foreach ($visible_files as $filename => $file) {
    $form['name'][$filename] = array(
      '#value' => $file->info['name'],
    );
    $form['version'][$filename] = array(
      '#value' => $file->info['version'],
    );
    $form['description'][$filename] = array(
      '#value' => t($file->info['description']),
    );
    $options[$filename] = '';

    // Ensure this module is compatible with this version of core and php.
    if (_system_is_incompatible($incompatible_core, $files, $file) || _system_is_incompatible($incompatible_php, $files, $file)) {
      $disabled[] = $file->name;

      // Nothing else in this loop matters, so move to the next module.
      continue;
    }
    if ($file->status) {
      $status[] = $file->name;
    }
    if ($file->throttle) {
      $throttle[] = $file->name;
    }
    $dependencies = array();

    // Check for missing dependencies.
    if (is_array($file->info['dependencies'])) {
      foreach ($file->info['dependencies'] as $dependency) {
        if (!isset($files[$dependency])) {
          $dependencies[] = t('@module (<span class="admin-missing">missing</span>)', array(
            '@module' => drupal_ucfirst($dependency),
          ));
          $disabled[] = $filename;
          $form['disabled_modules']['#value'][$filename] = FALSE;
        }
        elseif (isset($visible_files[$dependency])) {
          if ($files[$dependency]->status) {
            $dependencies[] = t('@module (<span class="admin-enabled">enabled</span>)', array(
              '@module' => $files[$dependency]->info['name'],
            ));
          }
          else {
            $dependencies[] = t('@module (<span class="admin-disabled">disabled</span>)', array(
              '@module' => $files[$dependency]->info['name'],
            ));
          }
        }
      }

      // Add text for dependencies.
      if (!empty($dependencies)) {
        $form['description'][$filename]['dependencies'] = array(
          '#value' => t('Depends on: !dependencies', array(
            '!dependencies' => implode(', ', $dependencies),
          )),
          '#prefix' => '<div class="admin-dependencies">',
          '#suffix' => '</div>',
        );
      }
    }

    // Mark dependents disabled so user can not remove modules being depended on.
    $dependents = array();
    foreach ($file->info['dependents'] as $dependent) {

      // Hidden modules are unset already.
      if (isset($visible_files[$dependent])) {
        if ($files[$dependent]->status == 1) {
          $dependents[] = t('@module (<span class="admin-enabled">enabled</span>)', array(
            '@module' => $files[$dependent]->info['name'],
          ));
          $disabled[] = $filename;
          $form['disabled_modules']['#value'][$filename] = TRUE;
        }
        else {
          $dependents[] = t('@module (<span class="admin-disabled">disabled</span>)', array(
            '@module' => $files[$dependent]->info['name'],
          ));
        }
      }
    }

    // Add text for enabled dependents.
    if (!empty($dependents)) {
      $form['description'][$filename]['required'] = array(
        '#value' => t('Required by: !required', array(
          '!required' => implode(', ', $dependents),
        )),
        '#prefix' => '<div class="admin-required">',
        '#suffix' => '</div>',
      );
    }
  }
  $modules_required = drupal_required_modules();

  // Merge in required modules.
  foreach ($modules_required as $required) {
    $disabled[] = $required;
    $form['disabled_modules']['#value'][$required] = TRUE;
  }

  // Handle status checkboxes, including overriding
  // the generated checkboxes for required modules.
  $form['status'] = array(
    '#type' => 'checkboxes',
    '#default_value' => $status,
    '#options' => $options,
    '#process' => array(
      'expand_checkboxes',
      'system_modules_disable',
    ),
    '#disabled_modules' => $disabled,
    '#incompatible_modules_core' => $incompatible_core,
    '#incompatible_modules_php' => $incompatible_php,
  );

  // Handle throttle checkboxes, including overriding the
  // generated checkboxes for required modules.
  if (module_exists('throttle')) {
    $form['throttle'] = array(
      '#type' => 'checkboxes',
      '#default_value' => $throttle,
      '#options' => $options,
      '#process' => array(
        'expand_checkboxes',
        'system_modules_disable',
      ),
      '#disabled_modules' => array_merge($modules_required, array(
        'throttle',
      )),
    );
  }
  $form['buttons']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );
  $form['#action'] = url('admin/build/modules/list/confirm');
  return $form;
}