diff --git a/oe_theme.theme b/oe_theme.theme index 8217b8689..c0f41b6ff 100644 --- a/oe_theme.theme +++ b/oe_theme.theme @@ -2555,27 +2555,29 @@ function oe_theme_page_attachments_alter(array &$attachments) { $oe_theme_path = \Drupal::service('extension.list.theme')->getPath('oe_theme'); $active_theme_path = $active_theme->getPath(); $component_library = theme_get_setting('component_library') ?? 'ec'; - $favicon = base_path() . $active_theme_path . "/images/favicons/$component_library/favicon.ico"; + $favicon = DRUPAL_ROOT . '/' . $active_theme_path . "/images/favicons/$component_library/favicon.ico"; foreach ($attachments['#attached']['html_head_link'] as &$link) { if ($link[0]['rel'] !== 'icon') { continue; } - $link[0]['href'] = file_exists($favicon) ? $favicon : base_path() . $oe_theme_path . "/images/favicons/$component_library/favicon.ico"; + // If subtheme file exists on the server, use its base path, otherwise + // use the base path of the base theme file. + $link[0]['href'] = file_exists($favicon) ? base_path() . $active_theme_path . "/images/favicons/$component_library/favicon.ico" : base_path() . $oe_theme_path . "/images/favicons/$component_library/favicon.ico"; } // Add the svg and png favicons. - $svg_favicon = base_path() . $active_theme_path . "/images/favicons/$component_library/favicon.svg"; + $svg_favicon = DRUPAL_ROOT . '/' . $active_theme_path . "/images/favicons/$component_library/favicon.svg"; $attachments['#attached']['html_head_link'][] = [ [ 'rel' => 'icon', - 'href' => file_exists($svg_favicon) ? $svg_favicon : base_path() . $oe_theme_path . "/images/favicons/$component_library/favicon.svg", + 'href' => file_exists($svg_favicon) ? base_path() . $active_theme_path . "/images/favicons/$component_library/favicon.svg" : base_path() . $oe_theme_path . "/images/favicons/$component_library/favicon.svg", 'type' => 'image/svg+xml', ], ]; - $png_favicon = base_path() . $active_theme_path . "/images/favicons/$component_library/favicon.png"; + $png_favicon = DRUPAL_ROOT . '/' . $active_theme_path . "/images/favicons/$component_library/favicon.png"; $attachments['#attached']['html_head_link'][] = [ [ 'rel' => 'apple-touch-icon', - 'href' => file_exists($png_favicon) ? $png_favicon : base_path() . $oe_theme_path . "/images/favicons/$component_library/favicon.png", + 'href' => file_exists($png_favicon) ? base_path() . $active_theme_path . "/images/favicons/$component_library/favicon.png" : base_path() . $oe_theme_path . "/images/favicons/$component_library/favicon.png", ], ]; } diff --git a/tests/src/Functional/ConfigurationTest.php b/tests/src/Functional/ConfigurationTest.php index e97875344..c16576e90 100755 --- a/tests/src/Functional/ConfigurationTest.php +++ b/tests/src/Functional/ConfigurationTest.php @@ -127,8 +127,8 @@ public function testChangeComponentLibrary(): void { $this->assertLinkNotContainsHref('/oe_theme/dist/eu/styles/optional/ecl-rtl.css'); // Assert that the favicon provided by the theme is being used. - $this->assertSession()->responseContains('/oe_theme/images/favicons/eu/favicon.ico'); - $this->assertSession()->responseContains('oe_theme/images/favicons/eu/favicon.png'); + $this->assertSession()->responseContains("/$active_theme/images/favicons/eu/favicon.ico"); + $this->assertSession()->responseContains('/oe_theme/images/favicons/eu/favicon.png'); $this->assertSession()->responseContains('/oe_theme/images/favicons/eu/favicon.svg'); // Assert that we do not load the EC component library. @@ -169,8 +169,8 @@ public function testChangeComponentLibrary(): void { $this->assertLinkNotContainsHref('/oe_theme/dist/ec/styles/optional/ecl-rtl.css'); // Assert that the favicon provided by the theme is being used. - $this->assertSession()->responseContains('/oe_theme/images/favicons/ec/favicon.ico'); - $this->assertSession()->responseContains('oe_theme/images/favicons/ec/favicon.png'); + $this->assertSession()->responseContains("/$active_theme/images/favicons/ec/favicon.ico"); + $this->assertSession()->responseContains('/oe_theme/images/favicons/ec/favicon.png'); $this->assertSession()->responseContains('/oe_theme/images/favicons/ec/favicon.svg'); // Assert that we do not load the EU component library by default. @@ -255,7 +255,7 @@ public function testUseEclFavicon(): void { $assert_session = $this->assertSession(); // Assert that the favicon provided by the base theme is being used. $this->drupalGet(''); - $assert_session->responseContains('/oe_theme/images/favicons/ec/favicon.ico'); + $assert_session->responseContains("/$active_theme/images/favicons/ec/favicon.ico"); $assert_session->responseContains('/oe_theme/images/favicons/ec/favicon.png'); $assert_session->responseContains('/oe_theme/images/favicons/ec/favicon.svg'); @@ -269,7 +269,7 @@ public function testUseEclFavicon(): void { // Assert that the favicon provided by the base theme is not being used. $this->drupalGet(''); - $assert_session->responseNotContains('/oe_theme/images/favicons/ec/favicon.ico'); + $assert_session->responseNotContains("/$active_theme/images/favicons/ec/favicon.ico"); $assert_session->responseNotContains('/oe_theme/images/favicons/ec/favicon.png'); $assert_session->responseNotContains('/oe_theme/images/favicons/ec/favicon.svg'); $assert_session->responseContains("https://www.w3schools.com/images/favicon.ico"); diff --git a/tests/themes/oe_theme_subtheme_test/favicon.ico b/tests/themes/oe_theme_subtheme_test/favicon.ico deleted file mode 100644 index 18f1b3167..000000000 Binary files a/tests/themes/oe_theme_subtheme_test/favicon.ico and /dev/null differ diff --git a/tests/themes/oe_theme_subtheme_test/images/favicons/ec/favicon.ico b/tests/themes/oe_theme_subtheme_test/images/favicons/ec/favicon.ico new file mode 100644 index 000000000..5b1bb43a3 Binary files /dev/null and b/tests/themes/oe_theme_subtheme_test/images/favicons/ec/favicon.ico differ diff --git a/tests/themes/oe_theme_subtheme_test/images/favicons/eu/favicon.ico b/tests/themes/oe_theme_subtheme_test/images/favicons/eu/favicon.ico new file mode 100644 index 000000000..c076906c0 Binary files /dev/null and b/tests/themes/oe_theme_subtheme_test/images/favicons/eu/favicon.ico differ