File tree Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ class BlocksField extends FieldClass
2626 use Min;
2727
2828 protected Fieldsets $ fieldsets ;
29+ protected array $ forms ;
2930 protected string |null $ group ;
3031 protected bool $ pretty ;
3132 protected mixed $ value = [];
@@ -51,19 +52,13 @@ public function blocksToValues(
5152 string $ to = 'toFormValues '
5253 ): array {
5354 $ result = [];
54- $ fields = [];
55- $ forms = [];
5655
5756 foreach ($ blocks as $ block ) {
5857 try {
59- $ type = $ block ['type ' ];
60-
61- // get and cache fields at the same time
62- $ fields [$ type ] ??= $ this ->fields ($ block ['type ' ]);
63- $ forms [$ type ] ??= $ this ->form ($ fields [$ type ]);
58+ $ form = $ this ->fieldsetForm ($ block ['type ' ]);
6459
6560 // overwrite the block content with form values
66- $ block ['content ' ] = $ forms [ $ type ] ->reset ()->fill (input: $ block ['content ' ])->$ to ();
61+ $ block ['content ' ] = $ form ->reset ()->fill (input: $ block ['content ' ])->$ to ();
6762
6863 // create id if not exists
6964 $ block ['id ' ] ??= Str::uuid ();
@@ -93,6 +88,11 @@ public function fieldset(string $type): Fieldset
9388 );
9489 }
9590
91+ protected function fieldsetForm (string $ type ): Form
92+ {
93+ return $ this ->forms [$ type ] ??= $ this ->form ($ this ->fields ($ type ));
94+ }
95+
9696 public function fieldsets (): Fieldsets
9797 {
9898 return $ this ->fieldsets ;
You can’t perform that action at this time.
0 commit comments