Skip to content

Commit 23058d7

Browse files
committed
[Icons] add xmnls attribute to svg icons
1 parent ab44abf commit 23058d7

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

src/Icons/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Add `aliases` configuration option to define icon alternative names.
66
- Add support for `int` and `float` attribute values in `<twig:ux:icon />`.
7+
- Add `xmlns` attribute in downloaded svg.
78

89
## 2.19.0
910

src/Icons/src/Iconify.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
final class Iconify
2727
{
2828
public const API_ENDPOINT = 'https://api.iconify.design';
29-
29+
public const XMLNS_URL = 'http://www.w3.org/2000/svg';
30+
3031
// URL must be 500 chars max (iconify limit)
3132
// -39 chars: https://api.iconify.design/XXX.json?icons=
3233
// -safe margin
@@ -90,6 +91,7 @@ public function fetchIcon(string $prefix, string $name): Icon
9091

9192
return new Icon($data['icons'][$name]['body'], [
9293
'viewBox' => \sprintf('0 0 %s %s', $width ?? $height, $height ?? $width),
94+
'xmlns' => self::XMLNS_URL,
9395
]);
9496
}
9597

@@ -137,6 +139,7 @@ public function fetchIcons(string $prefix, array $names): array
137139

138140
$icons[$iconName] = new Icon($iconData['body'], [
139141
'viewBox' => \sprintf('0 0 %d %d', $width ?? $height, $height ?? $width),
142+
'xmlns' => self::XMLNS_URL,
140143
]);
141144
}
142145

src/Icons/tests/Unit/IconifyTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function testFetchIcon(): void
4747
$icon = $iconify->fetchIcon('bi', 'heart');
4848

4949
$this->assertEquals($icon->getInnerSvg(), '<path d="M0 0h24v24H0z" fill="none"/>');
50-
$this->assertEquals($icon->getAttributes(), ['viewBox' => '0 0 24 24']);
50+
$this->assertEquals($icon->getAttributes(), ['viewBox' => '0 0 24 24', 'xmlns' => Iconify::XMLNS_URL]);
5151
}
5252

5353
public function testFetchIconByAlias(): void
@@ -78,7 +78,7 @@ public function testFetchIconByAlias(): void
7878
$icon = $iconify->fetchIcon('bi', 'foo');
7979

8080
$this->assertEquals($icon->getInnerSvg(), '<path d="M0 0h24v24H0z" fill="none"/>');
81-
$this->assertEquals($icon->getAttributes(), ['viewBox' => '0 0 24 24']);
81+
$this->assertEquals($icon->getAttributes(), ['viewBox' => '0 0 24 24', 'xmlns' => Iconify::XMLNS_URL]);
8282
}
8383

8484
public function testFetchIconThrowsWhenIconSetDoesNotExists(): void

0 commit comments

Comments
 (0)