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:
To only retrieve the default global theme setting, an empty string should be given for $theme.
$setting_name: The name of the setting to be retrieved.
$theme: The name of a given theme; defaults to the current theme.
The value of the requested setting, NULL if the setting does not exist.
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);
}