diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 27573e70aff41762492e39f6b96f820c76dca3ca..5f584196b184be974ebfb398837c0c72c5c4c7d6 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1343,8 +1343,15 @@ function template_preprocess_html(&$variables) { // Add a variable for the root path. This can be used to create a class and // theme the page depending on the current path (e.g. node, admin, user) as // well as more specific data like path-frontpage. - $path = \Drupal::request()->getPathInfo(); - $variables['root_path'] = explode('/', $path)[1]; + $is_front_page = \Drupal::service('path.matcher')->isFrontPage(); + + if ($is_front_page) { + $variables['root_path'] = TRUE; + } + else { + $system_path = \Drupal::request()->attributes->get('_system_path'); + $variables['root_path'] = explode('/', $system_path)[0]; + } $site_config = \Drupal::config('system.site'); // Construct page title. @@ -1356,7 +1363,7 @@ function template_preprocess_html(&$variables) { } // @todo Remove once views is not bypassing the view subscriber anymore. // @see http://drupal.org/node/2068471 - elseif (drupal_is_front_page()) { + elseif ($is_front_page) { $head_title = array( 'title' => t('Home'), 'name' => String::checkPlain($site_config->get('name')), diff --git a/core/modules/language/src/Tests/LanguageSwitchingTest.php b/core/modules/language/src/Tests/LanguageSwitchingTest.php index a39da666357a7d808c4a9799f2c1326c11d93ad7..d0e2a0d0e300f3dbfc5d2e22479a6aad65907235 100644 --- a/core/modules/language/src/Tests/LanguageSwitchingTest.php +++ b/core/modules/language/src/Tests/LanguageSwitchingTest.php @@ -163,7 +163,6 @@ protected function doTestLanguageBlockAnonymous($block_label) { /** * Test languge switcher links for domain based negotiation */ - function testLanguageBlockWithDomain() { // Add the Italian language. ConfigurableLanguage::createFromLangcode('it')->save(); @@ -241,6 +240,33 @@ function testLanguageLinkActiveClass() { $this->doTestLanguageLinkActiveClassAnonymous(); } + /** + * Check the path-admin class, as same as on default language. + */ + function testLanguageBodyClass() { + $searched_class = 'path-admin'; + + // Add language. + $edit = array( + 'predefined_langcode' => 'fr', + ); + $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language')); + + // Enable URL language detection and selection. + $edit = array('language_interface[enabled][language-url]' => '1'); + $this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings')); + + // Go to admin/config, check the class on default language. + $this->drupalGet('admin/config'); + $class = $this->xpath('//body[contains(@class, :class)]', array(':class' => $searched_class)); + $this->assertTrue(isset($class[0]), t('The path-admin class appears on default language.')); + + // Go to admin/config, check the class on french language. + $this->drupalGet('fr/admin/config'); + $class = $this->xpath('//body[contains(@class, :class)]', array(':class' => $searched_class)); + $this->assertTrue(isset($class[0]), t('The path-admin class same as on default language.')); + } + /** * For authenticated users, the "active" class is set by JavaScript. *