function ThemeSettingsProvider::buildThemeSettings
Build a ThemeSettings object for a given theme.
1 call to ThemeSettingsProvider::buildThemeSettings()
- ThemeSettingsProvider::getSetting in core/
lib/ Drupal/ Core/ Extension/ ThemeSettingsProvider.php
File
-
core/
lib/ Drupal/ Core/ Extension/ ThemeSettingsProvider.php, line 77
Class
- ThemeSettingsProvider
- Default implementation of the theme settings provider service.
Namespace
Drupal\Core\ExtensionCode
protected function buildThemeSettings(string $theme) : ThemeSettings {
// Create a theme settings object.
$themeSettings = new ThemeSettings($theme);
// Get the global settings from configuration.
$themeSettings->setData($this->configFactory
->get('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 = $this->themeHandler
->listInfo();
if (isset($themes[$theme])) {
$themeObject = $themes[$theme];
// Retrieve configured theme-specific settings, if any.
try {
if ($themeConfigSettings = $this->configFactory
->get($theme . '.settings')
->get()) {
$themeSettings->merge($themeConfigSettings);
}
} catch (StorageException) {
}
// If the theme does not support a particular feature, override the
// global setting and set the value to NULL.
if (!empty($themeObject->info['features'])) {
foreach (self::DEFAULT_THEME_FEATURES as $feature) {
if (!in_array($feature, $themeObject->info['features'])) {
$themeSettings->set('features.' . $feature, NULL);
}
}
}
// Generate the path to the logo image.
if ($themeSettings->get('logo.use_default')) {
$logo = $this->themeInitialization
->getActiveThemeByName($theme)
->getLogo();
$themeSettings->set('logo.url', $this->fileUrlGenerator
->generateString($logo));
}
elseif ($logo_path = $themeSettings->get('logo.path')) {
$themeSettings->set('logo.url', $this->fileUrlGenerator
->generateString($logo_path));
}
// Generate the path to the favicon.
if ($themeSettings->get('features.favicon')) {
$faviconPath = $themeSettings->get('favicon.path');
if ($themeSettings->get('favicon.use_default')) {
if (file_exists($favicon = $themeObject->getPath() . '/favicon.ico')) {
$themeSettings->set('favicon.url', $this->fileUrlGenerator
->generateString($favicon));
}
else {
$themeSettings->set('favicon.url', $this->fileUrlGenerator
->generateString('core/misc/favicon.ico'));
}
}
elseif ($faviconPath) {
$themeSettings->set('favicon.url', $this->fileUrlGenerator
->generateString($faviconPath));
}
else {
$themeSettings->set('features.favicon', FALSE);
}
}
}
return $themeSettings;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.