list_themes

Versions
4.6 – 7
list_themes($refresh = FALSE)

Return a list of all currently available themes.

Retrieved from the database, if available and the site is not in maintenance mode; otherwise compiled freshly from the filesystem.

Parameters

$refresh Whether to reload the list of themes from the database. Defaults to FALSE.

Return value

An associative array of the currently available themes. The keys are the names of the themes and the values are objects having the following properties:

  • 'filename': The name of the .info file.
  • 'name': The name of the theme.
  • 'status': 1 for enabled, 0 for disabled themes.
  • 'info': The contents of the .info file.
  • 'stylesheets': A two dimensional array, using the first key for the 'media' attribute (e.g. 'all'), the second for the name of the file (e.g. style.css). The value is a complete filepath (e.g. themes/garland/style.css).
  • 'scripts': An associative array of JavaScripts, using the filename as key and the complete filepath as value.
  • 'engine': The name of the theme engine.
  • 'base theme': The name of the base theme.

▾ 14 functions call list_themes()

block_add_block_form_submit in modules/block/block.admin.inc
Save the new custom block.
block_admin_configure in modules/block/block.admin.inc
Menu callback; displays the block configuration form.
block_help in modules/block/block.module
Implement hook_help().
block_menu in modules/block/block.module
Implement hook_menu().
drupal_find_theme_templates in includes/theme.inc
Allow themes and/or theme engines to easily discover overridden templates.
drupal_theme_initialize in includes/theme.inc
Initialize the theme system by loading the theme.
system_menu in modules/system/system.module
Implement hook_menu().
system_region_list in modules/system/system.module
Get a list of available regions from a specified theme.
system_themes_form_submit in modules/system/system.admin.inc
Process system_themes_form form submissions.
theme_get_setting in includes/theme.inc
Retrieve a setting for the current theme or for a given theme.
_color_html_alter in modules/color/color.module
Callback for the theme to alter the resources used.
_color_rewrite_stylesheet in modules/color/color.module
Rewrite the stylesheet to match the colors in the palette.
_color_theme_select_form_alter in modules/color/color.module
Helper for hook_form_FORM_ID_alter() implementations.
_drupal_maintenance_theme in includes/theme.maintenance.inc
Sets up the theming system for site installs, updates and when the site is in maintenance mode. It also applies when the database is unavailable.

Code

includes/theme.inc, line 559

<?php
function list_themes($refresh = FALSE) {
  static $list = array();

  if ($refresh) {
    $list = array();
    drupal_static_reset('system_list');
  }

  if (empty($list)) {
    $list = array();
    $themes = array();
    // Extract from the database only when it is available.
    // Also check that the site is not in the middle of an install or update.
    if (db_is_active() && !defined('MAINTENANCE_MODE')) {
      foreach (system_list('theme') as $theme) {
        if (file_exists($theme->filename)) {
          $theme->info = unserialize($theme->info);
          $themes[] = $theme;
        }
      }
    }
    else {
      // Scan the installation when the database should not be read.
      $themes = _system_rebuild_theme_data();
    }

    foreach ($themes as $theme) {
      foreach ($theme->info['stylesheets'] as $media => $stylesheets) {
        foreach ($stylesheets as $stylesheet => $path) {
          $theme->stylesheets[$media][$stylesheet] = $path;
        }
      }
      foreach ($theme->info['scripts'] as $script => $path) {
        if (file_exists($path)) {
          $theme->scripts[$script] = $path;
        }
      }
      if (isset($theme->info['engine'])) {
        $theme->engine = $theme->info['engine'];
      }
      if (isset($theme->info['base theme'])) {
        $theme->base_theme = $theme->info['base theme'];
      }
      // Status is normally retrieved from the database. Add zero values when
      // read from the installation directory to prevent notices.
      if (!isset($theme->status)) {
        $theme->status = 0;
      }
      $list[$theme->name] = $theme;
    }
  }

  return $list;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.