Skip to content

Commit be9a09a

Browse files
committed
ENH Allow a parent field to manage its child field state.
1 parent a1e76d5 commit be9a09a

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/Forms/Schema/FormSchema.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,18 @@ protected function getFieldStates($fields)
207207
{
208208
$states = [];
209209
foreach ($fields as $field) {
210-
$states[] = $field->getSchemaState();
210+
$fieldState = $field->getSchemaState();
211+
212+
// getSchema() allows fields to contain nested schema for their children.
213+
// The PHPDoc for getState says it should too - but it doesn't, and there are
214+
// backwards compatibility concerns with allowing that with the "children" array key.
215+
// Allow a special "child-state-to-fold-in" for nested data instead.
216+
if (isset($fieldState['child-state-to-fold-in'])) {
217+
$states = array_merge($states, $fieldState['child-state-to-fold-in']);
218+
unset($fieldState['child-state-to-fold-in']);
219+
}
220+
221+
$states[] = $fieldState;
211222

212223
if ($field instanceof CompositeField) {
213224
$subFields = $field->FieldList();

0 commit comments

Comments
 (0)