Skip to content

Commit 30b4a16

Browse files
authored
Merge pull request #94 from systopia/handle-const-and-default-values-like-in-other-fields
Handle const and default values for arrays like in other fields
2 parents 97ba73d + ae6d5ad commit 30b4a16

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/Form/Control/ArrayArrayFactory.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,19 @@ public function createFormArray(
7070
$form['#open'] = $definition->getOptionsValue('open', TRUE);
7171
}
7272

73+
if ((!$formState->isCached() || $definition->isReadOnly())) {
74+
$items = $definition->getConst() ?? $formState->getTemporaryValue($definition->getPropertyPath())
75+
?? $definition->getDefault();
76+
if (is_array($items)) {
77+
$items = array_map(fn ($item) => $item instanceof \stdClass ? (array) $item : $item, $items);
78+
$formState->setTemporaryValue($definition->getPropertyPath(), $items);
79+
}
80+
}
81+
7382
$propertyAccessor = FormStatePropertyAccessor::create($formState, $definition->getPropertyFormParents());
7483
$numItems = $propertyAccessor->getProperty('numItems');
7584
if (NULL === $numItems) {
76-
$items = $formState->getTemporaryValue($definition->getPropertyPath());
85+
$items ??= $formState->getTemporaryValue($definition->getPropertyPath());
7786
$numItems = is_array($items) ? count($items) : ($definition->getMinItems() ?? 0);
7887
$propertyAccessor->setProperty('numItems', $numItems);
7988
}

0 commit comments

Comments
 (0)