Skip to content

Commit 3495d3e

Browse files
author
matheo
committed
remove props from the attribute in the PropsNode
1 parent 97456bb commit 3495d3e

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/TwigComponent/src/ComponentAttributes.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public function __toString(): string
3737
function (string $carry, string $key) {
3838
$value = $this->attributes[$key];
3939

40+
if (!\is_scalar($value) && null !== $value) {
41+
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)));
42+
}
43+
4044
if (null === $value) {
4145
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.');
4246
$value = true;
@@ -146,4 +150,9 @@ public function add($stimulusDto): self
146150
// add the remaining attributes for values/classes
147151
return $clone->defaults($controllersAttributes);
148152
}
153+
154+
public function remove($key): void
155+
{
156+
unset($this->attributes[$key]);
157+
}
149158
}

src/TwigComponent/src/Twig/PropsNode.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public function compile(Compiler $compiler): void
4747
->write('$context[\''.$name.'\'] = ')
4848
->subcompile($this->getNode($name))
4949
->raw(";\n")
50+
->write('$context[\'attributes\']->remove(\''.$name.'\');')
5051
->write('}')
5152
;
5253
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<div class='user-card'>
1+
{% props user %}
2+
3+
<div {{ attributes }} class='user-card'>
24
<p>{{ user.name }}</p>
35
<p>{{ user.email }}</p>
46
</div>

0 commit comments

Comments
 (0)