function module_list

Returns a list of currently active modules.

Acts as a wrapper around system_list(), returning either a list of all enabled modules, or just modules needed for bootstrap.

The returned module list is always based on system_list(). The only exception to that is when a fixed list of modules has been passed in previously, in which case system_list() is omitted and the fixed list is always returned in subsequent calls until manually reverted via module_list_reset().

Parameters

string $type: The type of list to return:

  • module_enabled: All enabled modules.
  • bootstrap: All enabled modules required for bootstrap.

array $fixed_list: (optional) An array of module names to override the list of modules. This list will persist until the next call with a new $fixed_list passed in. Primarily intended for internal use (e.g., in install.php and update.php). Use module_list_reset() to undo the $fixed_list override.

bool $reset: (optional) Whether to reset/remove the $fixed_list.

Return value

array An associative array whose keys and values are the names of the modules in the list.

See also

module_list_reset()

32 calls to module_list()
authorize.php in drupal/core/authorize.php
Administrative script for running authorized file operations.
bootstrap_invoke_all in drupal/core/includes/bootstrap.inc
Invokes a bootstrap hook in all bootstrap modules that implement it.
breakpoint_enable in drupal/core/modules/breakpoint/breakpoint.install
Implements hook_enable().
DrupalUnitTestBase::enableModules in drupal/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php
Enables modules for this test.
DrupalUnitTestBaseTest::testEnableModulesInstall in drupal/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php
Tests expected installation behavior of enableModules().

... See full list

File

drupal/core/includes/module.inc, line 77
API for loading and interacting with Drupal modules.

Code

function module_list($type = 'module_enabled', array $fixed_list = NULL, $reset = FALSE) {

  // This static is only used for $fixed_list. It must not be a drupal_static(),
  // since any call to drupal_static_reset() in unit tests would cause an
  // attempt to retrieve the list of modules from the database (which does not
  // exist).
  static $module_list;
  if ($reset) {
    $module_list = NULL;

    // Do nothing if no $type and no $fixed_list have been passed.
    if (!isset($type) && !isset($fixed_list)) {
      return;
    }
  }

  // The list that will be be returned. Separate from $module_list in order
  // to not duplicate the static cache of system_list().
  $list = $module_list;
  if (isset($fixed_list)) {
    $module_list = array();
    foreach ($fixed_list as $name => $module) {
      system_register('module', $name, $module['filename']);
      $module_list[$name] = $name;
    }
    $list = $module_list;
  }
  elseif (!isset($module_list)) {
    $list = system_list($type);
  }
  return $list;
}