theme_get_setting

Versions
4.6 – 6
theme_get_setting($setting_name, $refresh = FALSE)
7
theme_get_setting($setting_name, $theme = NULL)

Retrieve a setting for the current theme or for a given theme.

The final setting is arrived at by merging the default settings, the custom theme settings defined in the theme's .info file, the site-wide settings, and the settings defined for the specific theme. If an empty string is given for $key, only the site-wide theme defaults are retrieved.

The default values for each setting is defined in this function. To add new settings, add their default values here, and then add form elements to system_theme_settings() in system.admin.inc.

Parameters

$setting_name The name of the setting to be retrieved.

$theme The name of a given theme; defaults to the current theme.

Return value

The value of the requested setting, NULL if the setting does not exist.

▾ 9 functions call theme_get_setting()

hook_form_system_theme_settings_alter in modules/system/system.api.php
Allow themes to alter the theme-specific settings form.
system_theme_settings in modules/system/system.admin.inc
Form builder; display theme configuration for entire site and individual themes.
system_update_7017 in modules/system/system.install
Change the theme setting 'toggle_node_info' into a per content type variable.
template_preprocess_comment in modules/comment/comment.module
Process variables for comment.tpl.php.
template_preprocess_html in includes/theme.inc
Preprocess variables for html.tpl.php
template_preprocess_maintenance_page in includes/theme.inc
The variables generated here is a mirror of template_preprocess_page(). This preprocessor will run it's course when theme_maintenance_page() is invoked. It is also used in theme_install_page() and theme_update_page() to keep all the variables...
template_preprocess_node in modules/node/node.module
Process variables for node.tpl.php
template_preprocess_page in includes/theme.inc
Preprocess variables for page.tpl.php
template_preprocess_username in includes/theme.inc
Preprocess variables for theme_username().

Code

includes/theme.inc, line 1135

<?php
function theme_get_setting($setting_name, $theme = NULL) {
  $cache = &drupal_static(__FUNCTION__, array());

  // If no key is given, use the current theme if we can determine it.
  if (is_null($theme)) {
    $theme = !empty($GLOBALS['theme_key']) ? $GLOBALS['theme_key'] : '';
  }

  if (empty($cache[$theme])) {
    // Set the default settings.
    $cache[$theme] = array(
      'default_logo'                     =>  1,
      'logo_path'                        =>  '',
      'default_favicon'                  =>  1,
      'favicon_path'                     =>  '',
      // Use the IANA-registered MIME type for ICO files as default.
      'favicon_mimetype'                 =>  'image/vnd.microsoft.icon',
      'main_menu'                        =>  1,
      'secondary_menu'                   =>  1,
      'toggle_logo'                      =>  1,
      'toggle_favicon'                   =>  1,
      'toggle_name'                      =>  1,
      'toggle_slogan'                    =>  1,
      'toggle_node_user_picture'         =>  1,
      'toggle_comment_user_picture'      =>  1,
      'toggle_comment_user_verification' =>  1,
      'toggle_main_menu'                 =>  1,
      'toggle_secondary_menu'            =>  1,
    );

    // Get the default values for the custom settings from the .info file.
    if ($theme) {
      $themes = list_themes();
      $theme_object = $themes[$theme];

      // Create a list which includes the current theme and all its base themes.
      if (isset($theme_object->base_themes)) {
        $theme_keys = array_keys($theme_object->base_themes);
        $theme_keys[] = $theme;
      }
      else {
        $theme_keys = array($theme);
      }
      foreach ($theme_keys as $theme_key) {
        if (!empty($themes[$theme_key]->info['settings'])) {
          $cache[$theme] = array_merge($cache[$theme], $themes[$theme_key]->info['settings']);
        }
      }
    }

    // Get the saved global settings from the database.
    $cache[$theme] = array_merge($cache[$theme], variable_get('theme_settings', array()));

    if ($theme) {
      // Get the saved theme settings from the database.
      $cache[$theme] = array_merge($cache[$theme], variable_get('theme_' . $theme . '_settings', array()));

      // Generate the path to the logo image.
      if ($cache[$theme]['toggle_logo']) {
        if ($cache[$theme]['default_logo']) {
          $cache[$theme]['logo'] = file_create_url(dirname($theme_object->filename) . '/logo.png');
        }
        elseif ($cache[$theme]['logo_path']) {
          $cache[$theme]['logo'] = file_create_url($cache[$theme]['logo_path']);
        }
      }

      // Generate the path to the favicon.
      if ($cache[$theme]['toggle_favicon']) {
        if ($cache[$theme]['default_favicon']) {
          if (file_exists($favicon = dirname($theme_object->filename) . '/favicon.ico')) {
            $cache[$theme]['favicon'] = file_create_url($favicon);
          }
          else {
            $cache[$theme]['favicon'] = file_create_url('misc/favicon.ico');
          }
        }
        elseif ($cache[$theme]['favicon_path']) {
          $cache[$theme]['favicon'] = file_create_url($cache[$theme]['favicon_path']);
        }
        else {
          $cache[$theme]['toggle_favicon'] = FALSE;
        }
      }
    }
  }

  return isset($cache[$theme][$setting_name]) ? $cache[$theme][$setting_name] : NULL;
}
?>
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.