Do minItem initialization before checking current value in repeater prep

Fixes https://github.com/octobercms/october/issues/5274
This commit is contained in:
Ben Thomson 2020-09-17 12:45:55 +08:00
parent 216b0d6004
commit ed06a6f1ac
No known key found for this signature in database
GPG Key ID: 8BDB18DD0909BE22
1 changed files with 10 additions and 10 deletions

View File

@ -248,16 +248,6 @@ class Repeater extends FormWidgetBase
}
}
if (!$this->childAddItemCalled && $currentValue === null) {
$this->formWidgets = [];
return;
}
if ($this->childAddItemCalled && !isset($currentValue[$this->childIndexCalled])) {
// If no value is available but a child repeater has added an item, add a "stub" repeater item
$this->makeItemFormWidget($this->childIndexCalled);
}
// Ensure that the minimum number of items are preinitialized
// ONLY DONE WHEN NOT IN GROUP MODE
if (!$this->useGroups && $this->minItems > 0) {
@ -273,6 +263,16 @@ class Repeater extends FormWidgetBase
}
}
if (!$this->childAddItemCalled && $currentValue === null) {
$this->formWidgets = [];
return;
}
if ($this->childAddItemCalled && !isset($currentValue[$this->childIndexCalled])) {
// If no value is available but a child repeater has added an item, add a "stub" repeater item
$this->makeItemFormWidget($this->childIndexCalled);
}
if (!is_array($currentValue)) {
return;
}