From ecccafa3191ef5fd18d0593935bfbb46b0a79386 Mon Sep 17 00:00:00 2001 From: Luke Towers Date: Mon, 1 Apr 2019 12:37:32 -0600 Subject: [PATCH] Fix issue where grouped repeaters stopped working in a recent build. Refs: https://github.com/octobercms/october/commit/13a7cc915db221b3ca67847fcdaaa4b71972e895#commitcomment-32986586 --- modules/backend/formwidgets/Repeater.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/backend/formwidgets/Repeater.php b/modules/backend/formwidgets/Repeater.php index 9d3fde0fe..83e4ebe0d 100644 --- a/modules/backend/formwidgets/Repeater.php +++ b/modules/backend/formwidgets/Repeater.php @@ -189,7 +189,11 @@ class Repeater extends FormWidgetBase if ($this->useGroups) { foreach ($value as $index => &$data) { $data['_group'] = $this->getGroupCodeFromIndex($index); + } + // Make sure the $data reference is removed from memory so that the next loop won't modify it + // which would cause the last item to receive the group code of the second-last item + unset($data); } if ($this->minItems && count($value) < $this->minItems) { @@ -204,7 +208,11 @@ class Repeater extends FormWidgetBase */ foreach ($value as $index => $data) { if (isset($this->formWidgets[$index])) { - $value[$index] = $this->formWidgets[$index]->getSaveData(); + if ($this->useGroups) { + $value[$index] = array_merge($this->formWidgets[$index]->getSaveData(), ['_group' => $data['_group']]); + } else { + $value[$index] = $this->formWidgets[$index]->getSaveData(); + } } }