function theme_get_setting in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/includes/theme.inc \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 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.
14 calls to theme_get_setting()
- color.inc in core/
themes/ bartik/ color/ color.inc - hook_form_system_theme_settings_alter in core/
lib/ Drupal/ Core/ Render/ theme.api.php - Allow themes to alter the theme-specific settings form.
- shortcut_preprocess_page_title in core/
modules/ shortcut/ shortcut.module - Implements hook_preprocess_HOOK() for page title templates.
- SystemBrandingBlock::build in core/
modules/ system/ src/ Plugin/ Block/ SystemBrandingBlock.php - Builds and returns the renderable array for this block plugin.
- system_page_attachments in core/
modules/ system/ system.module - Implements hook_page_attachments().
2 string references to 'theme_get_setting'
- ThemeInstaller::install in core/
lib/ Drupal/ Core/ Extension/ ThemeInstaller.php - Installs a given list of themes.
- ThemeInstaller::uninstall in core/
lib/ Drupal/ Core/ Extension/ ThemeInstaller.php - Uninstalls a given list of themes.
File
- core/
includes/ theme.inc, line 289 - 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_create_url($theme_object
->getPath() . '/logo.svg'));
}
elseif ($logo_path = $cache[$theme]
->get('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 = $theme_object
->getPath() . '/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);
}