Skip to content

Commit c7a708a

Browse files
committed
Leveraging the new PostMount in ComponentWithFormTrait!
1 parent 2e94d55 commit c7a708a

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/LiveComponent/src/ComponentWithFormTrait.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
1818
use Symfony\UX\LiveComponent\Attribute\BeforeReRender;
1919
use Symfony\UX\LiveComponent\Attribute\LiveProp;
20+
use Symfony\UX\LiveComponent\Util\ArrayUtil;
21+
use Symfony\UX\TwigComponent\Attribute\PostMount;
2022

2123
/**
2224
* @author Ryan Weaver <[email protected]>
@@ -63,23 +65,19 @@ trait ComponentWithFormTrait
6365
*/
6466
abstract protected function instantiateForm(): FormInterface;
6567

66-
/**
67-
* Override in your class if you need extra mounted values.
68-
*
69-
* If you override, call $this->initializeFormValues() manually
70-
* and also $this->formView = $form if you are passing in a Form.
71-
*
72-
* TODO: Refactor to PostMount when available.
73-
* https://github.com/symfony/ux/pull/220
74-
*/
75-
public function mount(FormView $form = null)
68+
#[PostMount]
69+
public function postMount(array $data): array
7670
{
77-
if ($form) {
78-
$this->formView = $form;
71+
// allow the FormView object to be passed into the component() as "form"
72+
if (array_key_exists('form', $data)) {
73+
$this->formView = $data['form'];
74+
unset($data['form']);
7975
}
8076

8177
// set the formValues from the initial form view's data
8278
$this->initializeFormValues();
79+
80+
return $data;
8381
}
8482

8583
/**

0 commit comments

Comments
 (0)