Same name and namespace in other branches
  1. 4.7.x includes/module.inc \module_list()
  2. 5.x includes/module.inc \module_list()
  3. 6.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.

Return value

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

4 calls to module_list()
file_download in includes/file.inc
Call modules to find out if a file is accessible for a given user.
module_exist in includes/module.inc
Determine whether a given module exists.
module_implements in includes/module.inc
Determine which modules are implementing a hook.
module_load_all in includes/module.inc
Load all the modules that have been enabled in the system table.

File

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

Code

function module_list($refresh = FALSE, $bootstrap = TRUE) {
  static $list;
  if ($refresh) {
    $list = array();
  }
  if (!$list) {
    $list = array(
      'filter' => 'filter',
      'system' => 'system',
      'user' => 'user',
      'watchdog' => 'watchdog',
    );
    if ($bootstrap) {
      $result = db_query("SELECT name, filename, throttle, bootstrap FROM {system} WHERE type = 'module' AND status = 1 AND bootstrap = 1");
    }
    else {
      $result = db_query("SELECT name, filename, throttle, bootstrap FROM {system} WHERE type = 'module' AND status = 1");
    }
    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;
        }
      }
    }
    asort($list);
  }
  return $list;
}