Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JMSITE-340: Do not force the library favicon if the theme is not conf… #1413

Open
wants to merge 1 commit into
base: 4.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions oe_theme.theme
Original file line number Diff line number Diff line change
Expand Up @@ -2572,6 +2572,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())) {
Expand Down
32 changes: 32 additions & 0 deletions tests/src/Functional/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('<front>');
$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('<front>');
$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.
*
Expand Down