From 757374efa2971c87d4a3a27872a4dee57974ae97 Mon Sep 17 00:00:00 2001 From: 22Alexandra Date: Thu, 5 Sep 2024 11:19:42 +0300 Subject: [PATCH] EWPP-4321: Fix the path built for file_exists(). --- oe_theme.theme | 14 ++++++++------ tests/src/Functional/ConfigurationTest.php | 12 ++++++------ tests/themes/oe_theme_subtheme_test/favicon.ico | Bin 656 -> 0 bytes .../images/favicons/ec/favicon.ico | Bin 0 -> 4286 bytes .../images/favicons/eu/favicon.ico | Bin 0 -> 4286 bytes 5 files changed, 14 insertions(+), 12 deletions(-) delete mode 100644 tests/themes/oe_theme_subtheme_test/favicon.ico create mode 100644 tests/themes/oe_theme_subtheme_test/images/favicons/ec/favicon.ico create mode 100644 tests/themes/oe_theme_subtheme_test/images/favicons/eu/favicon.ico 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 18f1b31674b76e6fec1bfd2559efce458d55d405..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 656 zcmV;B0&o3^P)1RCwBA{Qv(y!$1Nih5-hn4j6C; zu(0?qIxwIP0Al+g8wL9Ej~MJVZ_w8P`5rsrmd{U{%`gv${f*C}$kEIJeKAWJdZU+t z>5C8L7(RUC0*h}vYs^p=w4R|Za6Q;T0$krnN&^G|$Uu-~AWJVjk^|EqkTf$D#Ssp` z=m7CSSV80s!-F>>1kGk-_FMR$P&~)m9%gt5G;IG>Erv^vW#JCO=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c7QMI&l3i_!`>53R+CNlKK;0AT^&RHU0J_9ou!2imIubEH$>zYXj8@>%~QPUuQvL(ptFlDQe(>B8xZ2TKQ71>V! literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..c076906c091c00a6fa5bd98d4fa23beec7d92357 GIT binary patch literal 4286 zcmeHKOHWfl6rLg)1x=J{A&^L2D1@L9#YP}V3lyV}Qb>$}uv6=6LvSV51~Brllt(dD zaBbq!g+IiY7{jkQo^NiaxoPUm+(o&IdYf|}XTF*5obSv`ra}bx7Y+;D#kaFUgoF^C zZ0r(IHu&YmZB31iIgbDLT32BIrVu_`9rFj-nvdAP3GNWv54J!IF_4pdAyUB$2(*nx8HKCpN#XwUx*y1`MEf~yLXvB z_tsG&lcCACX?_pT%Ka#`uOV7XO8`@UK z!V;TK_Ly|A;z#^jcbaHnc9^woG}acFh1r|N-p%tB)VyIJtzA*@l>pt75`>5L^H2m$hvCAD&+~x`@5I8 z&r8~jUeLvC6_wzjlgc^E?NxR>ZlqvdSNL=)c!@iay;s#`|ms*EJ-^2B(SzKJ3B3 z?DaLsJ}$1({BZfK`OybF*nbDN4=9y-Aipz-Yo$D&JblP*`&HS0Rm@n=$Uip}lxsVg zUZklvujM=Hj{FU4-mQbD{8bEY%`qQgN*`4Vg*7}Czu)H%zt3NOpFe#)f7kl|pIXnK M%C2hbQAS690kECskpKVy literal 0 HcmV?d00001