function theme_get_setting

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

18 calls to theme_get_setting()
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_preprocess_block in core/themes/olivero/olivero.theme
Implements hook_preprocess_HOOK() for block.html.twig.
olivero_preprocess_html in core/themes/olivero/olivero.theme
Implements hook_preprocess_HOOK() for HTML document templates.
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.

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

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) {
            }
            // 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.