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

EWPP-3652: Add favicon in ico, svg and png formats based on component library. #1326

Merged
merged 1 commit into from
Oct 17, 2023
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ docker-compose.*.yml
# Ignore all files in the images folder other than listed below.

/images/*
!/images/favicons
!/images/required.svg
!/images/user_icon.svg
/.gitattributes
Binary file removed favicon.ico
Binary file not shown.
Binary file added images/favicons/ec/favicon.ico
Binary file not shown.
Binary file added images/favicons/ec/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 78 additions & 0 deletions images/favicons/ec/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/favicons/eu/favicon.ico
Binary file not shown.
Binary file added images/favicons/eu/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions images/favicons/eu/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions oe_theme.theme
Original file line number Diff line number Diff line change
Expand Up @@ -2388,3 +2388,34 @@ function oe_theme_preprocess_select(&$variables) {
];
}
}

/**
* Implements hook_page_attachments_alter().
*/
function oe_theme_page_attachments_alter(array &$attachments) {
// 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())) {
$component_library = theme_get_setting('component_library') ?? 'ec';
foreach ($attachments['#attached']['html_head_link'] as &$link) {
if ($link[0]['rel'] !== 'icon') {
continue;
}
$link[0]['href'] = base_path() . $active_theme->getPath() . "/images/favicons/$component_library/favicon.ico";
}
// Add the svg and png favicons.
$attachments['#attached']['html_head_link'][] = [
[
'rel' => 'icon',
'href' => base_path() . $active_theme->getPath() . "/images/favicons/$component_library/favicon.svg",
'type' => 'image/svg+xml',
],
];
$attachments['#attached']['html_head_link'][] = [
[
'rel' => 'apple-touch-icon',
'href' => base_path() . $active_theme->getPath() . "/images/favicons/$component_library/favicon.png",
],
];
}
}
8 changes: 6 additions & 2 deletions tests/src/Functional/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ 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('/' . $active_theme . '/favicon.ico');
$this->assertSession()->responseContains("/$active_theme/images/favicons/eu/favicon.ico");
$this->assertSession()->responseContains("$active_theme/images/favicons/eu/favicon.png");
$this->assertSession()->responseContains("/$active_theme/images/favicons/eu/favicon.svg");

// Assert that we do not load the EC component library.
$this->assertLinkNotContainsHref('/oe_theme/dist/ec/styles/ecl-ec.css');
Expand Down Expand Up @@ -167,7 +169,9 @@ 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('/' . $active_theme . '/favicon.ico');
$this->assertSession()->responseContains("/$active_theme/images/favicons/ec/favicon.ico");
$this->assertSession()->responseContains("$active_theme/images/favicons/ec/favicon.png");
$this->assertSession()->responseContains("/$active_theme/images/favicons/ec/favicon.svg");

// Assert that we do not load the EU component library by default.
$this->assertLinkNotContainsHref('/oe_theme/dist/eu/styles/ecl-eu.css');
Expand Down