Skip to content

Commit 585194f

Browse files
committed
remove need for HasAttributesTrait PreMount hook
1 parent c0cd6ac commit 585194f

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/TwigComponent/src/HasAttributesTrait.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Symfony\UX\LiveComponent\Attribute\LiveProp;
1515
use Symfony\UX\TwigComponent\Attribute\PostMount;
16-
use Symfony\UX\TwigComponent\Attribute\PreMount;
1716

1817
/**
1918
* @author Kevin Bond <[email protected]>
@@ -25,23 +24,19 @@ trait HasAttributesTrait
2524
#[LiveProp(hydrateWith: 'hydrateAttributes', dehydrateWith: 'dehydrateAttributes')]
2625
public ComponentAttributes $attributes;
2726

28-
#[PreMount]
29-
public function preMountAttributes(array $data): array
27+
public function setAttributes(array $attributes): void
3028
{
31-
$data['_attributes'] = $data['attributes'] ?? [];
32-
33-
unset($data['attributes']);
34-
35-
return $data;
29+
$this->attributes = new ComponentAttributes($attributes);
3630
}
3731

3832
#[PostMount(priority: -1000)]
3933
public function mountAttributes(array $data): array
4034
{
41-
$attributes = array_merge($data['_attributes'], $data);
42-
unset($attributes['_attributes']);
35+
if (isset($this->attributes)) {
36+
$data = array_merge($this->attributes->all(), $data);
37+
}
4338

44-
$this->attributes = new ComponentAttributes($attributes);
39+
$this->attributes = new ComponentAttributes($data);
4540

4641
return [];
4742
}

0 commit comments

Comments
 (0)