diff --git a/core/modules/system/system.tokens.inc b/core/modules/system/system.tokens.inc index 722e03147b..ab6e9d68b6 100644 --- a/core/modules/system/system.tokens.inc +++ b/core/modules/system/system.tokens.inc @@ -7,7 +7,6 @@ * This file handles tokens for the global 'site' and 'date' tokens. */ -use Drupal\Component\Utility\Html; use Drupal\Core\Datetime\Entity\DateFormat; use Drupal\Core\Render\BubbleableMetadata; @@ -44,12 +43,10 @@ function system_token_info() { $site['logo'] = [ 'name' => t("Logo"), 'description' => t("The default site logo [site:logo], or for a provided theme [site:logo:?] (Available themes: @themes).", ['@themes' => $themes_formatted]), - 'dynamic' => TRUE, ]; $site['logo-url'] = [ 'name' => t("Logo URL"), 'description' => t("The URL of the default site logo [site:logo-url], or for a provided theme [site:logo-url:?] (Available themes: @themes).", ['@themes' => $themes_formatted]), - 'dynamic' => TRUE, ]; $site['url'] = [ 'name' => t("URL"), @@ -144,8 +141,7 @@ function system_tokens($type, $tokens, array $data, array $options, BubbleableMe case 'logo': $default_theme = \Drupal::config('system.theme')->get('default'); - $theme = _system_tokens_get_actual_theme($default_theme, $bubbleable_metadata); - $logo_url = theme_get_setting('logo.url', $theme); + $logo_url = _system_tokens_get_actual_logo($default_theme, $bubbleable_metadata); $build = [ '#theme' => 'image', @@ -156,8 +152,7 @@ function system_tokens($type, $tokens, array $data, array $options, BubbleableMe case 'logo-url': $default_theme = \Drupal::config('system.theme')->get('default'); - $theme = _system_tokens_get_actual_theme($default_theme, $bubbleable_metadata); - $replacements[$original] = theme_get_setting('logo.url', $theme); + $replacements[$original] = _system_tokens_get_actual_logo($default_theme, $bubbleable_metadata); break; case 'url': @@ -190,8 +185,7 @@ function system_tokens($type, $tokens, array $data, array $options, BubbleableMe foreach ($created_tokens as $theme => $original) { // See if the requested theme was enabled. if (isset($themes[$theme])) { - $theme = _system_tokens_get_actual_theme($theme, $bubbleable_metadata); - $logo_url = theme_get_setting('logo.url', $theme); + $logo_url = _system_tokens_get_actual_logo($theme, $bubbleable_metadata); $build = [ '#theme' => 'image', '#uri' => $logo_url, @@ -208,8 +202,7 @@ function system_tokens($type, $tokens, array $data, array $options, BubbleableMe foreach ($created_tokens as $theme => $original) { // See if the requested theme was enabled. if (isset($themes[$theme])) { - $theme = _system_tokens_get_actual_theme($theme, $bubbleable_metadata); - $replacements[$original] = theme_get_setting('logo.url', $theme); + $replacements[$original] = _system_tokens_get_actual_logo($theme, $bubbleable_metadata); } } } @@ -266,18 +259,15 @@ function system_tokens($type, $tokens, array $data, array $options, BubbleableMe * @return string|null * The theme name, or NULL if the selected theme has no custom logo. */ -function _system_tokens_get_actual_theme($theme, BubbleableMetadata &$bubbleable_metadata) { +function _system_tokens_get_actual_logo($theme, BubbleableMetadata &$bubbleable_metadata) { // Retrieve configurations. $config = \Drupal::config('system.theme.global'); $theme_config = \Drupal::config($theme . '.settings'); $bubbleable_metadata->addCacheableDependency($config); $bubbleable_metadata->addCacheableDependency($theme_config); - // If there is no logo key, we set the theme to NULL to use the global - // fallback. - if (!$theme_config->get('logo.path')) { - $theme = NULL; - } + $default_theme = $config->get('default'); - return $theme; + // If there is no logo, we use the default theme as fallback. + return theme_get_setting('logo.url', $theme) ?: theme_get_setting('logo.url', $default_theme); }