diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 4c0e580..5bb97ca 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1445,32 +1445,48 @@ function theme_get_setting($setting_name, $theme = NULL) { } } + // A dummy query-string is added to filenames, to gain control over + // browser-caching. The string changes on every update or full cache + // flush, forcing browsers to load a new copy of the files, as the + // URL changed. + $query_string = state()->get('system.css_js_query_string') ?: '0'; + // Generate the path to the logo image. if ($cache[$theme]['toggle_logo']) { + $logo_path = ''; if ($cache[$theme]['default_logo']) { - $cache[$theme]['logo'] = file_create_url(dirname($theme_object->filename) . '/logo.png'); + $logo_path = file_create_url(dirname($theme_object->filename) . '/logo.png'); } elseif ($cache[$theme]['logo_path']) { - $cache[$theme]['logo'] = file_create_url($cache[$theme]['logo_path']); + $logo_path = file_create_url($cache[$theme]['logo_path']); + } + if (!empty($logo_path)) { + $query_string_separator = (strpos($logo_path, '?') !== FALSE) ? '&' : '?'; + $cache[$theme]['logo'] = $logo_path . $query_string_separator . $query_string; } } // Generate the path to the favicon. if ($cache[$theme]['toggle_favicon']) { + $favicon_path = ''; if ($cache[$theme]['default_favicon']) { if (file_exists($favicon = dirname($theme_object->filename) . '/favicon.ico')) { - $cache[$theme]['favicon'] = file_create_url($favicon); + $favicon_path = file_create_url($favicon); } else { - $cache[$theme]['favicon'] = file_create_url('core/misc/favicon.ico'); + $favicon_path = file_create_url('core/misc/favicon.ico'); } } elseif ($cache[$theme]['favicon_path']) { - $cache[$theme]['favicon'] = file_create_url($cache[$theme]['favicon_path']); + $favicon_path = file_create_url($cache[$theme]['favicon_path']); } else { $cache[$theme]['toggle_favicon'] = FALSE; } + if (!empty($favicon_path)) { + $query_string_separator = (strpos($favicon_path, '?') !== FALSE) ? '&' : '?'; + $cache[$theme]['favicon'] = $favicon_path . $query_string_separator . $query_string; + } } } } diff --git a/core/modules/system/lib/Drupal/system/Tests/System/ThemeTest.php b/core/modules/system/lib/Drupal/system/Tests/System/ThemeTest.php index f636849..91f7cad 100644 --- a/core/modules/system/lib/Drupal/system/Tests/System/ThemeTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/System/ThemeTest.php @@ -48,31 +48,34 @@ function testThemeSettings() { $file_relative = strtr($file->uri, array('public:/' => variable_get('file_public_path', conf_path() . '/files'))); $default_theme_path = 'core/themes/stark'; + // Logo's and favicons receive a query string. + $query_string = variable_get('css_js_query_string', '0'); + $supported_paths = array( // Raw stream wrapper URI. $file->uri => array( 'form' => file_uri_target($file->uri), - 'src' => file_create_url($file->uri), + 'src' => file_create_url($file->uri) . '?' . $query_string, ), // Relative path within the public filesystem. file_uri_target($file->uri) => array( 'form' => file_uri_target($file->uri), - 'src' => file_create_url($file->uri), + 'src' => file_create_url($file->uri) . '?' . $query_string, ), // Relative path to a public file. $file_relative => array( 'form' => $file_relative, - 'src' => file_create_url($file->uri), + 'src' => file_create_url($file->uri) . '?' . $query_string, ), // Relative path to an arbitrary file. 'core/misc/druplicon.png' => array( 'form' => 'core/misc/druplicon.png', - 'src' => $GLOBALS['base_url'] . '/' . 'core/misc/druplicon.png', + 'src' => $GLOBALS['base_url'] . '/' . 'core/misc/druplicon.png' . '?' . $query_string, ), // Relative path to a file in a theme. $default_theme_path . '/logo.png' => array( 'form' => $default_theme_path . '/logo.png', - 'src' => $GLOBALS['base_url'] . '/' . $default_theme_path . '/logo.png', + 'src' => $GLOBALS['base_url'] . '/' . $default_theme_path . '/logo.png' . '?' . $query_string, ), ); foreach ($supported_paths as $input => $expected) { @@ -164,7 +167,7 @@ function testThemeSettings() { $this->drupalGet(''); $elements = $this->xpath('//*[@id=:id]/img', array(':id' => 'logo')); - $this->assertEqual($elements[0]['src'], file_create_url($uploaded_filename)); + $this->assertEqual($elements[0]['src'], file_create_url($uploaded_filename) . '?' . $query_string); } /**