Same name and namespace in other branches
  1. 4.6.x includes/module.inc \module_list()
  2. 4.7.x includes/module.inc \module_list()
  3. 5.x includes/module.inc \module_list()
  4. 7.x includes/module.inc \module_list()

Collect a list of all loaded modules. During the bootstrap, return only vital modules. See bootstrap.inc

Parameters

$refresh: Whether to force the module list to be regenerated (such as after the administrator has changed the system settings).

$bootstrap: Whether to return the reduced set of modules loaded in "bootstrap mode" for cached pages. See bootstrap.inc.

$sort: By default, modules are ordered by weight and filename, settings this option to TRUE, module list will be ordered by module name.

$fixed_list: (Optional) Override the module list with the given modules. Stays until the next call with $refresh = TRUE.

Return value

An associative array whose keys and values are the names of all loaded modules.

12 calls to module_list()
install_main in ./install.php
The Drupal installation happens in a series of steps. We begin by verifying that the current environment meets our minimum requirements. We then go on to verify that settings.php is properly configured. From there we connect to the configured database…
module_disable in includes/module.inc
Disable a given set of modules.
module_enable in includes/module.inc
Enable a given list of modules.
module_exists in includes/module.inc
Determine whether a given module exists.
module_implements in includes/module.inc
Determine which modules are implementing a hook.

... See full list

File

includes/module.inc, line 46
API for loading and interacting with Drupal modules.

Code

function module_list($refresh = FALSE, $bootstrap = TRUE, $sort = FALSE, $fixed_list = NULL) {
  static $list, $sorted_list;
  if ($refresh || $fixed_list) {
    $list = array();
    $sorted_list = NULL;
    if ($fixed_list) {
      foreach ($fixed_list as $name => $module) {
        drupal_get_filename('module', $name, $module['filename']);
        $list[$name] = $name;
      }
    }
    else {
      if ($bootstrap) {
        $result = db_query("SELECT name, filename, throttle FROM {system} WHERE type = 'module' AND status = 1 AND bootstrap = 1 ORDER BY weight ASC, filename ASC");
      }
      else {
        $result = db_query("SELECT name, filename, throttle FROM {system} WHERE type = 'module' AND status = 1 ORDER BY weight ASC, filename ASC");
      }
      while ($module = db_fetch_object($result)) {
        if (file_exists($module->filename)) {

          // Determine the current throttle status and see if the module should be
          // loaded based on server load. We have to directly access the throttle
          // variables, since throttle.module may not be loaded yet.
          $throttle = $module->throttle && variable_get('throttle_level', 0) > 0;
          if (!$throttle) {
            drupal_get_filename('module', $module->name, $module->filename);
            $list[$module->name] = $module->name;
          }
        }
      }
    }
  }
  if ($sort) {
    if (!isset($sorted_list)) {
      $sorted_list = $list;
      ksort($sorted_list);
    }
    return $sorted_list;
  }
  return $list;
}