function theme_get_setting

theme_get_setting($setting_name, $theme = NULL)

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 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.

File

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

Code

function theme_get_setting($setting_name, $theme = NULL) {
  /** @var \Drupal\Core\Theme\ThemeSettings[] $cache */
  $cache = &drupal_static(__FUNCTION__, array());

  // If no key is given, use the current theme if we can determine it.
  if (!isset($theme)) {
    $theme = \Drupal::theme()->getActiveTheme()->getName();
  }

  if (empty($cache[$theme])) {
    // Create a theme settings object.
    $cache[$theme] = new ThemeSettings($theme);
    // Get the global settings from configuration.
    $cache[$theme]->setData(\Drupal::config('system.theme.global')->get());

    // Get the values for the theme-specific settings from the .info.yml files
    // of the theme and all its base themes.
    $themes = \Drupal::service('theme_handler')->listInfo();
    if (isset($themes[$theme])) {
      $theme_object = $themes[$theme];

      // Retrieve configured theme-specific settings, if any.
      try {
        if ($theme_settings = \Drupal::config($theme . '.settings')->get()) {
          $cache[$theme]->merge($theme_settings);
        }
      }
      catch (StorageException $e) {
      }

      // If the theme does not support a particular feature, override the global
      // setting and set the value to NULL.
      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('logo.use_default')) {
        $cache[$theme]->set('logo.url', file_url_transform_relative(file_create_url($theme_object->getPath() . '/logo.svg')));
      }
      elseif ($logo_path = $cache[$theme]->get('logo.path')) {
        $cache[$theme]->set('logo.url', file_url_transform_relative(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 = $theme_object->getPath() . '/favicon.ico')) {
            $cache[$theme]->set('favicon.url', file_url_transform_relative(file_create_url($favicon)));
          }
          else {
            $cache[$theme]->set('favicon.url', file_url_transform_relative(file_create_url('core/misc/favicon.ico')));
          }
        }
        elseif ($favicon_path) {
          $cache[$theme]->set('favicon.url', file_url_transform_relative(file_create_url($favicon_path)));
        }
        else {
          $cache[$theme]->set('features.favicon', FALSE);
        }
      }
    }
  }

  return $cache[$theme]->get($setting_name);
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!includes!theme.inc/function/theme_get_setting/8.1.x