Skip to content

Commit

Permalink
EWPP-4321: Fix the path built for file_exists().
Browse files Browse the repository at this point in the history
  • Loading branch information
22Alexandra committed Sep 5, 2024
1 parent 94d8b6f commit 757374e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
14 changes: 8 additions & 6 deletions oe_theme.theme
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
];
}
Expand Down
12 changes: 6 additions & 6 deletions tests/src/Functional/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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('<front>');
$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');

Expand All @@ -269,7 +269,7 @@ public function testUseEclFavicon(): void {

// Assert that the favicon provided by the base theme is not being used.
$this->drupalGet('<front>');
$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");
Expand Down
Binary file removed tests/themes/oe_theme_subtheme_test/favicon.ico
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 757374e

Please sign in to comment.