module_list
Definition
module_list($refresh = FALSE, $bootstrap = TRUE, $sort = FALSE, $fixed_list = NULL)
includes/module.inc, line 48
Description
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. Set this option to TRUE to return a module list ordered only 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.
Code
<?php
function module_list($refresh = FALSE, $bootstrap = TRUE, $sort = FALSE, $fixed_list = NULL) {
static $list = array(), $sorted_list;
if (empty($list) || $refresh || $fixed_list) {
unset($sorted_list);
$list = array();
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 FROM {system} WHERE type = 'module' AND status = 1 AND bootstrap = 1 ORDER BY weight ASC, filename ASC");
}
else {
$result = db_query("SELECT name, filename 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)) {
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;
}
?> 