diff --git a/src/Icons/CHANGELOG.md b/src/Icons/CHANGELOG.md index 8ff2aad1fb0..48a8ba77b5a 100644 --- a/src/Icons/CHANGELOG.md +++ b/src/Icons/CHANGELOG.md @@ -1,5 +1,11 @@ # CHANGELOG +## 2.24.0 + +- Add `xmlns` attribute to icons downloaded with Iconify, to correctly render icons browser as an external file, in SVG editors, and in files explorers or text editors previews. +It **may breaks your pipeline** if you assert on `ux_icon()` or `` output in your tests, and forgot [to lock your icons](https://symfony.com/bundles/ux-icons/current/index.html#locking-on-demand-icons). +We recommend you to **lock** your icons **before** upgrading to UX Icons 2.24. We also suggest you to to **force-lock** your icons **after** upgrading to UX Icons 2.24, to add the attribute `xmlns` to your icons already downloaded from Iconify. + ## 2.20.0 - Add `aliases` configuration option to define icon alternative names. diff --git a/src/Icons/src/Iconify.php b/src/Icons/src/Iconify.php index fcbebe81031..55c5051d335 100644 --- a/src/Icons/src/Iconify.php +++ b/src/Icons/src/Iconify.php @@ -26,6 +26,7 @@ final class Iconify { public const API_ENDPOINT = 'https://api.iconify.design'; + private const ATTR_XMLNS_URL = 'https://www.w3.org/2000/svg'; // URL must be 500 chars max (iconify limit) // -39 chars: https://api.iconify.design/XXX.json?icons= @@ -89,6 +90,7 @@ public function fetchIcon(string $prefix, string $name): Icon } return new Icon($data['icons'][$name]['body'], [ + 'xmlns' => self::ATTR_XMLNS_URL, 'viewBox' => \sprintf('0 0 %s %s', $width ?? $height, $height ?? $width), ]); } @@ -136,6 +138,7 @@ public function fetchIcons(string $prefix, array $names): array $width = $iconData['width'] ?? $data['width'] ??= $this->sets()[$prefix]['width'] ?? null; $icons[$iconName] = new Icon($iconData['body'], [ + 'xmlns' => self::ATTR_XMLNS_URL, 'viewBox' => \sprintf('0 0 %d %d', $width ?? $height, $height ?? $width), ]); } diff --git a/src/Icons/tests/Integration/RenderIconsInTwigTest.php b/src/Icons/tests/Integration/RenderIconsInTwigTest.php index 8789f29a150..feba3097dbe 100644 --- a/src/Icons/tests/Integration/RenderIconsInTwigTest.php +++ b/src/Icons/tests/Integration/RenderIconsInTwigTest.php @@ -33,8 +33,8 @@ public function testRenderIcons(): void
  • -
  • -
  • +
  • +
  • HTML, trim($output) @@ -49,7 +49,7 @@ public function testRenderAliasIcons(): void $templateAlias = ''; $outputAlias = self::getContainer()->get(Environment::class)->createTemplate($templateAlias)->render(); - $expected = ''; + $expected = ''; $this->assertSame($outputIcon, $expected); $this->assertSame($outputIcon, $outputAlias); } diff --git a/src/Icons/tests/Unit/IconifyTest.php b/src/Icons/tests/Unit/IconifyTest.php index c57e37ccccb..cec6172cb7d 100644 --- a/src/Icons/tests/Unit/IconifyTest.php +++ b/src/Icons/tests/Unit/IconifyTest.php @@ -47,7 +47,7 @@ public function testFetchIcon(): void $icon = $iconify->fetchIcon('bi', 'heart'); $this->assertEquals($icon->getInnerSvg(), ''); - $this->assertEquals($icon->getAttributes(), ['viewBox' => '0 0 24 24']); + $this->assertEquals($icon->getAttributes(), ['viewBox' => '0 0 24 24', 'xmlns' => 'https://www.w3.org/2000/svg']); } public function testFetchIconByAlias(): void @@ -78,7 +78,7 @@ public function testFetchIconByAlias(): void $icon = $iconify->fetchIcon('bi', 'foo'); $this->assertEquals($icon->getInnerSvg(), ''); - $this->assertEquals($icon->getAttributes(), ['viewBox' => '0 0 24 24']); + $this->assertEquals($icon->getAttributes(), ['viewBox' => '0 0 24 24', 'xmlns' => 'https://www.w3.org/2000/svg']); } public function testFetchIconThrowsWhenIconSetDoesNotExists(): void