You are here

function system_list in Drupal 7

Same name and namespace in other branches
  1. 8 core/includes/module.inc \system_list()

Builds a list of bootstrap modules and enabled modules and themes.

Parameters

$type: The type of list to return:

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

Return value

An associative array of modules or themes, keyed by name. For $type 'bootstrap', the array values equal the keys. For $type 'module_enabled' or 'theme', the array values are objects representing the respective database row, with the 'info' property already unserialized.

See also

module_list()

list_themes()

4 calls to system_list()
list_themes in includes/theme.inc
Returns a list of all currently available themes.
module_list in includes/module.inc
Returns a list of currently active modules.
SystemInfoAlterTestCase::testSystemInfoAlter in modules/system/system.test
Tests that {system}.info is rebuilt after a module that implements hook_system_info_alter() is enabled. Also tests if core *_list() functions return freshly altered info.
system_get_info in modules/system/system.module
Returns an array of information about enabled modules or themes.
5 string references to 'system_list'
module_list in includes/module.inc
Returns a list of currently active modules.
system_list_reset in includes/module.inc
Resets all system_list() caches.
system_schema in modules/system/system.install
Implements hook_schema().
system_update_7062 in modules/system/system.install
Replace 'system_list' index with 'bootstrap' index on {system}.
update_fix_d7_requirements in includes/update.inc
Perform Drupal 6.x to 7.x updates that are required for update.php to function properly.

File

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

Code

function system_list($type) {
  $lists =& drupal_static(__FUNCTION__);

  // For bootstrap modules, attempt to fetch the list from cache if possible.
  // if not fetch only the required information to fire bootstrap hooks
  // in case we are going to serve the page from cache.
  if ($type == 'bootstrap') {
    if (isset($lists['bootstrap'])) {
      return $lists['bootstrap'];
    }
    if ($cached = cache_get('bootstrap_modules', 'cache_bootstrap')) {
      $bootstrap_list = $cached->data;
    }
    else {
      $bootstrap_list = db_query("SELECT name, filename FROM {system} WHERE status = 1 AND bootstrap = 1 AND type = 'module' ORDER BY weight ASC, name ASC")
        ->fetchAllAssoc('name');
      cache_set('bootstrap_modules', $bootstrap_list, 'cache_bootstrap');
    }

    // To avoid a separate database lookup for the filepath, prime the
    // drupal_get_filename() static cache for bootstrap modules only.
    // The rest is stored separately to keep the bootstrap module cache small.
    foreach ($bootstrap_list as $module) {
      drupal_get_filename('module', $module->name, $module->filename);
    }

    // We only return the module names here since module_list() doesn't need
    // the filename itself.
    $lists['bootstrap'] = array_keys($bootstrap_list);
  }
  elseif (!isset($lists['module_enabled'])) {
    if ($cached = cache_get('system_list', 'cache_bootstrap')) {
      $lists = $cached->data;
    }
    else {
      $lists = array(
        'module_enabled' => array(),
        'theme' => array(),
        'filepaths' => array(),
      );

      // The module name (rather than the filename) is used as the fallback
      // weighting in order to guarantee consistent behavior across different
      // Drupal installations, which might have modules installed in different
      // locations in the file system. The ordering here must also be
      // consistent with the one used in module_implements().
      $result = db_query("SELECT * FROM {system} WHERE type = 'theme' OR (type = 'module' AND status = 1) ORDER BY weight ASC, name ASC");
      foreach ($result as $record) {
        $record->info = unserialize($record->info);

        // Build a list of all enabled modules.
        if ($record->type == 'module') {
          $lists['module_enabled'][$record->name] = $record;
        }

        // Build a list of themes.
        if ($record->type == 'theme') {
          $lists['theme'][$record->name] = $record;
        }

        // Build a list of filenames so drupal_get_filename can use it.
        if ($record->status) {
          $lists['filepaths'][] = array(
            'type' => $record->type,
            'name' => $record->name,
            'filepath' => $record->filename,
          );
        }
      }
      foreach ($lists['theme'] as $key => $theme) {
        if (!empty($theme->info['base theme'])) {

          // Make a list of the theme's base themes.
          require_once DRUPAL_ROOT . '/includes/theme.inc';
          $lists['theme'][$key]->base_themes = drupal_find_base_themes($lists['theme'], $key);

          // Don't proceed if there was a problem with the root base theme.
          if (!current($lists['theme'][$key]->base_themes)) {
            continue;
          }

          // Determine the root base theme.
          $base_key = key($lists['theme'][$key]->base_themes);

          // Add to the list of sub-themes for each of the theme's base themes.
          foreach (array_keys($lists['theme'][$key]->base_themes) as $base_theme) {
            $lists['theme'][$base_theme]->sub_themes[$key] = $lists['theme'][$key]->info['name'];
          }

          // Add the base theme's theme engine info.
          $lists['theme'][$key]->info['engine'] = isset($lists['theme'][$base_key]->info['engine']) ? $lists['theme'][$base_key]->info['engine'] : 'theme';
        }
        else {

          // A plain theme is its own engine.
          $base_key = $key;
          if (!isset($lists['theme'][$key]->info['engine'])) {
            $lists['theme'][$key]->info['engine'] = 'theme';
          }
        }

        // Set the theme engine prefix.
        $lists['theme'][$key]->prefix = $lists['theme'][$key]->info['engine'] == 'theme' ? $base_key : $lists['theme'][$key]->info['engine'];
      }
      cache_set('system_list', $lists, 'cache_bootstrap');
    }

    // To avoid a separate database lookup for the filepath, prime the
    // drupal_get_filename() static cache with all enabled modules and themes.
    foreach ($lists['filepaths'] as $item) {
      drupal_get_filename($item['type'], $item['name'], $item['filepath']);
    }
  }
  return $lists[$type];
}