2020use Symfony \UX \LiveComponent \Storage \StorageInterface ;
2121use Symfony \UX \TwigComponent \Attribute \ExposeInTemplate ;
2222use Symfony \UX \TwigComponent \Attribute \PostMount ;
23+
2324use function Symfony \Component \String \u ;
2425
2526/**
2930 */
3031trait 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 ());
0 commit comments