Skip to content

Commit 20ef568

Browse files
committed
Fix
1 parent 0d280f9 commit 20ef568

File tree

4 files changed

+26
-22
lines changed

4 files changed

+26
-22
lines changed

src/LiveComponent/src/ComponentWithMultiStepFormTrait.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Symfony\UX\LiveComponent\Storage\StorageInterface;
2121
use Symfony\UX\TwigComponent\Attribute\ExposeInTemplate;
2222
use Symfony\UX\TwigComponent\Attribute\PostMount;
23+
2324
use function Symfony\Component\String\u;
2425

2526
/**
@@ -29,8 +30,8 @@
2930
*/
3031
trait ComponentWithMultiStepFormTrait
3132
{
32-
use DefaultActionTrait;
3333
use ComponentWithFormTrait;
34+
use DefaultActionTrait;
3435

3536
#[LiveProp]
3637
public ?string $currentStepName = null;
@@ -49,19 +50,19 @@ public function hasValidationErrors(): bool
4950
/**
5051
* @internal
5152
*
52-
* Must be executed after ComponentWithFormTrait::initializeForm().
53+
* Must be executed after ComponentWithFormTrait::initializeForm()
5354
*/
5455
#[PostMount(priority: -250)]
5556
public function initialize(): void
5657
{
5758
$this->currentStepName = $this->getStorage()->get(
58-
sprintf('%s_current_step_name', self::prefix()),
59+
\sprintf('%s_current_step_name', self::prefix()),
5960
$this->formView->vars['current_step_name'],
6061
);
6162

6263
$this->form = $this->instantiateForm();
6364

64-
$formData = $this->getStorage()->get(sprintf(
65+
$formData = $this->getStorage()->get(\sprintf(
6566
'%s_form_values_%s',
6667
self::prefix(),
6768
$this->currentStepName,
@@ -91,7 +92,7 @@ public function next(): void
9192
}
9293

9394
$this->getStorage()->persist(
94-
sprintf('%s_form_values_%s', self::prefix(), $this->currentStepName),
95+
\sprintf('%s_form_values_%s', self::prefix(), $this->currentStepName),
9596
$this->form->getData(),
9697
);
9798

@@ -117,13 +118,13 @@ public function next(): void
117118
}
118119

119120
$this->currentStepName = $next;
120-
$this->getStorage()->persist(sprintf('%s_current_step_name', self::prefix()), $this->currentStepName);
121+
$this->getStorage()->persist(\sprintf('%s_current_step_name', self::prefix()), $this->currentStepName);
121122

122123
// If we have a next step, we need to resinstantiate the form and reset the form view and values.
123124
$this->form = $this->instantiateForm();
124125
$this->formView = null;
125126

126-
$formData = $this->getStorage()->get(sprintf(
127+
$formData = $this->getStorage()->get(\sprintf(
127128
'%s_form_values_%s',
128129
self::prefix(),
129130
$this->currentStepName,
@@ -165,12 +166,12 @@ public function previous(): void
165166
}
166167

167168
$this->currentStepName = $previous;
168-
$this->getStorage()->persist(sprintf('%s_current_step_name', self::prefix()), $this->currentStepName);
169+
$this->getStorage()->persist(\sprintf('%s_current_step_name', self::prefix()), $this->currentStepName);
169170

170171
$this->form = $this->instantiateForm();
171172
$this->formView = null;
172173

173-
$formData = $this->getStorage()->get(sprintf(
174+
$formData = $this->getStorage()->get(\sprintf(
174175
'%s_form_values_%s',
175176
self::prefix(),
176177
$this->currentStepName,
@@ -202,7 +203,7 @@ public function submit(): void
202203
}
203204

204205
$this->getStorage()->persist(
205-
sprintf('%s_form_values_%s', self::prefix(), $this->currentStepName),
206+
\sprintf('%s_form_values_%s', self::prefix(), $this->currentStepName),
206207
$this->form->getData(),
207208
);
208209

@@ -219,7 +220,7 @@ public function getAllData(): array
219220
$data = [];
220221

221222
foreach ($this->stepNames as $stepName) {
222-
$data[$stepName] = $this->getStorage()->get(sprintf(
223+
$data[$stepName] = $this->getStorage()->get(\sprintf(
223224
'%s_form_values_%s',
224225
self::prefix(),
225226
$stepName,
@@ -232,12 +233,12 @@ public function getAllData(): array
232233
public function resetForm(): void
233234
{
234235
foreach ($this->stepNames as $stepName) {
235-
$this->getStorage()->remove(sprintf('%s_form_values_%s', self::prefix(), $stepName));
236+
$this->getStorage()->remove(\sprintf('%s_form_values_%s', self::prefix(), $stepName));
236237
}
237238

238-
$this->getStorage()->remove(sprintf('%s_current_step_name', self::prefix()));
239+
$this->getStorage()->remove(\sprintf('%s_current_step_name', self::prefix()));
239240

240-
$this->currentStepName = $this->stepNames[\array_key_first($this->stepNames)];
241+
$this->currentStepName = $this->stepNames[array_key_first($this->stepNames)];
241242
$this->form = $this->instantiateForm();
242243
$this->formView = null;
243244
$this->formValues = $this->extractFormValues($this->getFormView());

src/LiveComponent/src/Form/Type/MultiStepType.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22

3+
4+
declare(strict_types=1);
5+
36
/*
47
* This file is part of the Symfony package.
58
*
@@ -9,8 +12,6 @@
912
* file that was distributed with this source code.
1013
*/
1114

12-
declare(strict_types=1);
13-
1415
namespace Symfony\UX\LiveComponent\Form\Type;
1516

1617
use Symfony\Component\Form\AbstractType;
@@ -31,7 +32,7 @@ public function configureOptions(OptionsResolver $resolver): void
3132
{
3233
$resolver
3334
->setDefault('current_step_name', static function (Options $options): string {
34-
return \array_key_first($options['steps']);
35+
return array_key_first($options['steps']);
3536
})
3637
->setRequired('steps');
3738
}
@@ -44,6 +45,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
4445
public function buildView(FormView $view, FormInterface $form, array $options): void
4546
{
4647
$view->vars['current_step_name'] = $options['current_step_name'];
47-
$view->vars['steps_names'] = \array_keys($options['steps']);
48+
$view->vars['steps_names'] = array_keys($options['steps']);
4849
}
4950
}

src/LiveComponent/src/Storage/SessionStorage.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22

3+
4+
declare(strict_types=1);
5+
36
/*
47
* This file is part of the Symfony package.
58
*
@@ -9,8 +12,6 @@
912
* file that was distributed with this source code.
1013
*/
1114

12-
declare(strict_types=1);
13-
1415
namespace Symfony\UX\LiveComponent\Storage;
1516

1617
use Symfony\Component\HttpFoundation\RequestStack;

src/LiveComponent/src/Storage/StorageInterface.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22

3+
4+
declare(strict_types=1);
5+
36
/*
47
* This file is part of the Symfony package.
58
*
@@ -9,8 +12,6 @@
912
* file that was distributed with this source code.
1013
*/
1114

12-
declare(strict_types=1);
13-
1415
namespace Symfony\UX\LiveComponent\Storage;
1516

1617
/**

0 commit comments

Comments
 (0)