File tree Expand file tree Collapse file tree
src/Implementation/Component/Input/Field
tests/Component/Input/Field Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -140,12 +140,14 @@ public function withValue($value): HasDynamicInputs
140140 $ this ->checkArg ("value " , $ this ->isClientSideValueOk ($ value ), "Display value does not match input type. " );
141141
142142 $ clone = clone $ this ;
143- foreach ($ value as $ data ) {
144- $ file_id = ($ clone ->hasMetadataInputs ()) ? $ data [0 ] : $ data ;
143+ if (is_array ($ value )) {
144+ foreach ($ value as $ data ) {
145+ $ file_id = ($ clone ->hasMetadataInputs ()) ? $ data [0 ] : $ data ;
145146
146- // that was not implicitly intended, but mapping dynamic inputs
147- // to the file-id is also a duplicate protection.
148- $ clone ->generated_dynamic_inputs [$ file_id ] = $ clone ->getTemplateForDynamicInputs ()->withValue ($ data );
147+ // that was not implicitly intended, but mapping dynamic inputs
148+ // to the file-id is also a duplicate protection.
149+ $ clone ->generated_dynamic_inputs [$ file_id ] = $ clone ->getTemplateForDynamicInputs ()->withValue ($ data );
150+ }
149151 }
150152
151153 return $ clone ;
Original file line number Diff line number Diff line change @@ -95,15 +95,15 @@ public function withValue($value): self
9595 $ this ->checkArg ('value ' , $ this ->isClientSideValueOk ($ value ), "Display value does not match input(-template) type. " );
9696 $ clone = clone $ this ;
9797
98- if (!is_array ($ value )) {
98+ if (is_array ($ value )) {
99+ foreach ($ value as $ input_name => $ input_value ) {
100+ $ clone ->generated_dynamic_inputs [$ input_name ] = $ clone ->getTemplateForDynamicInputs ()->withValue ($ input_value );
101+ }
102+ } elseif ($ value !== null ) {
99103 $ clone ->generated_dynamic_inputs [] = $ clone ->getTemplateForDynamicInputs ()->withValue ($ value );
100104 return $ clone ;
101105 }
102106
103- foreach ($ value as $ input_name => $ input_value ) {
104- $ clone ->generated_dynamic_inputs [$ input_name ] = $ clone ->getTemplateForDynamicInputs ()->withValue ($ input_value );
105- }
106-
107107 return $ clone ;
108108 }
109109
Original file line number Diff line number Diff line change @@ -156,6 +156,14 @@ public function testWithValueForValidArguments(string|int|null $value): void
156156 $ this ->assertEquals ([$ value ], $ component ->getValue ());
157157 }
158158
159+ public function testWithValueForEmptyValidArguments (): void
160+ {
161+ $ node_retrieval = $ this ->getNodeRetrieval ();
162+ $ component = $ this ->getFieldFactory ()->treeSelect ($ node_retrieval , '' );
163+ $ component = $ component ->withValue (null );
164+ $ this ->assertEquals ([], $ component ->getValue ());
165+ }
166+
159167 public function testRenderWithValue (): void
160168 {
161169 $ node_id = 'some-existing-node-id ' ;
@@ -332,7 +340,6 @@ public static function getValidArgumentsForWithValue(): array
332340 ['1 ' ],
333341 ['' ],
334342 [' ' ],
335- [null ],
336343 ];
337344 }
338345
You can’t perform that action at this time.
0 commit comments