system_modules

Definition

system_modules($form_state = array())
modules/system/system.admin.inc, line 619

Description

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.

See also

drupal_parse_info_file for information on module.info descriptors.

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.

See also

theme_system_modules()

@see system_modules_submit()

Parameters

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

Return value

The form array.

Related topics

Namesort iconDescription
Form builder functionsFunctions that build an abstract representation of a HTML form.

Code

<?php
function system_modules($form_state = array()) {
  drupal_rebuild_theme_registry();
  node_types_rebuild();
  menu_rebuild();
  cache_clear_all('schema', 'cache');
  // Get current list of modules.
  $files = module_rebuild_cache();

  uasort($files, 'system_sort_modules_by_info_name');

  if (!empty($form_state['storage'])) {
    return system_modules_confirm_form($files, $form_state['storage']);
  }
  $dependencies = array();

  // Store module list for validation callback.
  $form['validation_modules'] = array('#type' => 'value', '#value' => $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 ($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 ($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]) || !$files[$dependency]->status) {
          if (isset($files[$dependency])) {
            $dependencies[] = $files[$dependency]->info['name'] . t(' (<span class="admin-disabled">disabled</span>)');
          }
          else {
            $dependencies[] = drupal_ucfirst($dependency) . t(' (<span class="admin-missing">missing</span>)');
            $disabled[] = $filename;
            $form['disabled_modules']['#value'][$filename] = FALSE;
          }
        }
        else {
          $dependencies[] = $files[$dependency]->info['name'] . t(' (<span class="admin-enabled">enabled</span>)');
        }
      }

      // 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) {
      if ($files[$dependent]->status == 1) {
        $dependents[] = $files[$dependent]->info['name'] . t(' (<span class="admin-enabled">enabled</span>)');
        $disabled[] = $filename;
        $form['disabled_modules']['#value'][$filename] = TRUE;
      }
      else {
        $dependents[] = $files[$dependent]->info['name'] . t(' (<span class="admin-disabled">disabled</span>)');
      }
    }

    // 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;
}
?>
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.