Skip to content

Commit 57ff749

Browse files
committed
fix(twig): bc break
1 parent cd3c550 commit 57ff749

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/TwigComponent/src/ComponentAttributes.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ public function __toString(): string
3939
function (string $carry, string $key) {
4040
$value = $this->attributes[$key];
4141

42+
if (null === $value) {
43+
trigger_deprecation('symfony/ux-twig-component', '2.8.0', 'Passing "null" as an attribute value is deprecated and will throw an exception in 3.0.');
44+
$value = true;
45+
}
46+
4247
return match ($value) {
4348
true => "{$carry} {$key}",
4449
false => $carry,
@@ -170,16 +175,11 @@ private function ensureNormalized(): self
170175
private static function normalize(array &$attributes): void
171176
{
172177
foreach ($attributes as $key => &$value) {
173-
if (null === $value) {
174-
trigger_deprecation('symfony/ux-twig-component', '2.8.0', 'Passing "null" as an attribute value is deprecated and will throw an exception in 3.0.');
175-
$value = true;
176-
}
177-
178178
if (\is_array($value) && array_is_list($value)) {
179179
$value = implode(' ', array_filter($value, static fn ($v) => \is_string($v) && '' !== $v));
180180
}
181181

182-
if (!\is_scalar($value)) {
182+
if (!\is_scalar($value) && null !== $value) {
183183
throw new \LogicException(sprintf('A "%s" prop was passed when creating the component. No matching "%s" property or mount() argument was found, so we attempted to use this as an HTML attribute. But, the value is not a scalar (it\'s a %s). Did you mean to pass this to your component or is there a typo on its name?', $key, $key, get_debug_type($value)));
184184
}
185185
}

src/TwigComponent/tests/Unit/ComponentAttributesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public function testNullBehaviour(): void
188188
{
189189
$attributes = new ComponentAttributes(['disabled' => null]);
190190

191-
$this->assertSame(['disabled' => true], $attributes->all());
191+
$this->assertSame(['disabled' => null], $attributes->all());
192192
$this->assertSame(' disabled', (string) $attributes);
193193
}
194194

0 commit comments

Comments
 (0)