function theme_get_setting

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

The final setting is obtained from the last value found in the following sources:

  • the default theme-specific settings defined in any base theme's .info.yml file
  • the default theme-specific settings defined in the theme's .info.yml file
  • the saved values from the global theme settings form
  • the saved values from the theme's settings form

To only retrieve the default global theme setting, an empty string should be given for $theme.

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.

13 calls to theme_get_setting()
bartik_process_maintenance_page in drupal/core/themes/bartik/bartik.theme
Implements hook_process_HOOK() for maintenance-page.html.twig.
bartik_process_page in drupal/core/themes/bartik/bartik.theme
Implements hook_process_HOOK() for page.html.twig.
color.inc in drupal/core/themes/bartik/color/color.inc
Lists avalable colors and color schemes for the Bartik theme.
hook_form_system_theme_settings_alter in drupal/core/modules/system/theme.api.php
Allow themes to alter the theme-specific settings form.
shortcut_preprocess_page in drupal/core/modules/shortcut/shortcut.module
Implements hook_preprocess_HOOK() for page.tpl.php.

... See full list

File

drupal/core/includes/theme.inc, line 1363
The theme system, which controls the output of Drupal.

Code

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 (!isset($theme)) {
    $theme = !empty($GLOBALS['theme_key']) ? $GLOBALS['theme_key'] : '';
  }
  if (empty($cache[$theme])) {

    // Create a theme settings object.
    $cache[$theme] = new ThemeSettings($theme);

    // Get the values for the theme-specific settings from the .info.yml files
    // of the theme and all its base themes.
    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]
            ->mergeData($themes[$theme_key]->info['settings']);
        }
      }
    }

    // Get the global settings from configuration.
    $cache[$theme]
      ->mergeData(Drupal::config('system.theme.global')
      ->get());
    if ($theme) {

      // Get the saved theme-specific settings from the configuration system.
      $cache[$theme]
        ->mergeData(Drupal::config($theme . '.settings')
        ->get());

      // If the theme does not support a particular feature, override the global
      // setting and set the value to NULL.

      //$supports = $cache[$theme]->get('supports');
      if (!empty($theme_object->info['features'])) {
        foreach (_system_default_theme_features() as $feature) {
          if (!in_array($feature, $theme_object->info['features'])) {
            $cache[$theme]
              ->set('features.' . $feature, NULL);
          }
        }
      }

      // Generate the path to the logo image.
      if ($cache[$theme]
        ->get('features.logo')) {
        $logo_path = $cache[$theme]
          ->get('logo.path');
        if ($cache[$theme]
          ->get('logo.use_default')) {
          $cache[$theme]
            ->set('logo.url', file_create_url(dirname($theme_object->filename) . '/logo.png'));
        }
        elseif ($logo_path) {
          $cache[$theme]
            ->set('logo.url', file_create_url($logo_path));
        }
      }

      // Generate the path to the favicon.
      if ($cache[$theme]
        ->get('features.favicon')) {
        $favicon_path = $cache[$theme]
          ->get('favicon.path');
        if ($cache[$theme]
          ->get('favicon.use_default')) {
          if (file_exists($favicon = dirname($theme_object->filename) . '/favicon.ico')) {
            $cache[$theme]
              ->set('favicon.url', file_create_url($favicon));
          }
          else {
            $cache[$theme]
              ->set('favicon.url', file_create_url('core/misc/favicon.ico'));
          }
        }
        elseif ($favicon_path) {
          $cache[$theme]
            ->set('favicon.url', file_create_url($favicon_path));
        }
        else {
          $cache[$theme]
            ->set('features.favicon', FALSE);
        }
      }
    }
  }
  return $cache[$theme]
    ->get($setting_name);
}