From ed06a6f1ac94c219e37a16e74325cf0a89bbe73e Mon Sep 17 00:00:00 2001 From: Ben Thomson Date: Thu, 17 Sep 2020 12:45:55 +0800 Subject: [PATCH] Do minItem initialization before checking current value in repeater prep Fixes https://github.com/octobercms/october/issues/5274 --- modules/backend/formwidgets/Repeater.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/backend/formwidgets/Repeater.php b/modules/backend/formwidgets/Repeater.php index 95ac67c90..159f20c3e 100644 --- a/modules/backend/formwidgets/Repeater.php +++ b/modules/backend/formwidgets/Repeater.php @@ -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; }