diff --git a/oe_theme.theme b/oe_theme.theme index 2fdb491f8..e95a22fa6 100644 --- a/oe_theme.theme +++ b/oe_theme.theme @@ -2465,6 +2465,11 @@ function oe_theme_preprocess_select(&$variables) { * Implements hook_page_attachments_alter(). */ function oe_theme_page_attachments_alter(array &$attachments) { + // If the theme is configured to not use the theme favicon, bail out. + if (!theme_get_setting('favicon.use_default')) { + return; + } + // Use different favicon based on theme component library. $active_theme = \Drupal::theme()->getActiveTheme(); if ($active_theme->getName() === 'oe_theme' || array_key_exists('oe_theme', $active_theme->getBaseThemeExtensions())) { diff --git a/tests/src/Functional/ConfigurationTest.php b/tests/src/Functional/ConfigurationTest.php index 915caed8e..3d55041e1 100755 --- a/tests/src/Functional/ConfigurationTest.php +++ b/tests/src/Functional/ConfigurationTest.php @@ -245,6 +245,38 @@ public function testChangeEclBranding(): void { } } + /** + * Test that the correct favicon is used based on theme configuration. + */ + public function testUseEclFavicon(): void { + foreach (['oe_theme', 'oe_theme_subtheme_test'] as $active_theme) { + $this->config('system.theme')->set('default', $active_theme)->save(); + $this->container->set('theme.registry', NULL); + $assert_session = $this->assertSession(); + $page = $this->getSession()->getPage(); + // Assert that the favicon provided by the theme is being used. + $this->drupalGet(''); + $assert_session->responseContains("/$active_theme/images/favicons/ec/favicon.ico"); + $assert_session->responseContains("$active_theme/images/favicons/ec/favicon.png"); + $assert_session->responseContains("/$active_theme/images/favicons/ec/favicon.svg"); + + // Configure theme to not use default favicon. + $this->config("$active_theme.settings")->set('favicon', [ + 'mimetype' => 'image/vnd.microsoft.icon', + 'path' => 'https://www.w3schools.com/images/favicon.ico', + 'use_default' => FALSE, + ])->save(); + $this->container->set('theme.registry', NULL); + + // Assert that the favicon provided by the theme is not being used. + $this->drupalGet(''); + $assert_session->responseNotContains("/$active_theme/images/favicons/ec/favicon.ico"); + $assert_session->responseNotContains("$active_theme/images/favicons/ec/favicon.png"); + $assert_session->responseNotContains("/$active_theme/images/favicons/ec/favicon.svg"); + $assert_session->responseContains("https://www.w3schools.com/images/favicon.ico"); + } + } + /** * Assert that current response contians a link tag with given href. *