function theme_get_setting

Same name in other branches
  1. 7.x includes/theme.inc \theme_get_setting()
  2. 8.9.x core/includes/theme.inc \theme_get_setting()
  3. 10 core/includes/theme.inc \theme_get_setting()
  4. 11.x 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

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

21 calls to theme_get_setting()
color.inc in core/themes/bartik/color/color.inc
Lists available colors and color schemes for the Bartik theme.
color.inc in core/modules/color/tests/modules/color_test/themes/color_test_theme/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.
olivero_form_system_theme_settings_alter in core/themes/olivero/theme-settings.php
Implements hook_form_FORM_ID_alter() for system_theme_settings.
olivero_preprocess_block in core/themes/olivero/olivero.theme
Implements hook_preprocess_HOOK() for block.html.twig.

... See full list

3 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.
ThemeSettingsTest::testLogoConfig in core/tests/Drupal/KernelTests/Core/Theme/ThemeSettingsTest.php
Tests that the default logo config can be overridden.

File

core/includes/theme.inc, line 313

Code

function theme_get_setting($setting_name, $theme = NULL) {
    
    /** @var \Drupal\Core\Theme\ThemeSettings[] $cache */
    $cache =& drupal_static(__FUNCTION__, []);
    // 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);
                    }
                }
            }
            
            /** @var \Drupal\Core\File\FileUrlGeneratorInterface $file_url_generator */
            $file_url_generator = \Drupal::service('file_url_generator');
            // Generate the path to the logo image.
            if ($cache[$theme]->get('logo.use_default')) {
                $logo = \Drupal::service('theme.initialization')->getActiveThemeByName($theme)
                    ->getLogo();
                $cache[$theme]->set('logo.url', $file_url_generator->generateString($logo));
            }
            elseif ($logo_path = $cache[$theme]->get('logo.path')) {
                $cache[$theme]->set('logo.url', $file_url_generator->generateString($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_generator->generateString($favicon));
                    }
                    else {
                        $cache[$theme]->set('favicon.url', $file_url_generator->generateString('core/misc/favicon.ico'));
                    }
                }
                elseif ($favicon_path) {
                    $cache[$theme]->set('favicon.url', $file_url_generator->generateString($favicon_path));
                }
                else {
                    $cache[$theme]->set('features.favicon', FALSE);
                }
            }
        }
    }
    return $cache[$theme]->get($setting_name);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.