Skip to content

Commit

Permalink
Merge pull request #1326 from openeuropa/EWPP-3652
Browse files Browse the repository at this point in the history
EWPP-3652: Add favicon in ico, svg and png formats based on component library.
  • Loading branch information
upchuk authored Oct 17, 2023
2 parents 3d2f449 + fa16ffd commit 61c9762
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 2 deletions.
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

0 comments on commit 61c9762

Please sign in to comment.