From 6a6378a24d3b47b29c5c452d1424b22e6d5fe3b6 Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Wed, 26 Apr 2017 08:10:45 +1000 Subject: [PATCH] Strip indexes from repeater data sets --- modules/backend/formwidgets/Repeater.php | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/modules/backend/formwidgets/Repeater.php b/modules/backend/formwidgets/Repeater.php index b3ff113c5..dd9bf7b82 100644 --- a/modules/backend/formwidgets/Repeater.php +++ b/modules/backend/formwidgets/Repeater.php @@ -151,13 +151,12 @@ class Repeater extends FormWidgetBase */ protected function processSaveValue($value) { - if (!$this->useGroups || !is_array($value) || !$value) { + if (!is_array($value) || !$value) { return $value; } - foreach ($value as $index => &$data) { - $data['_index'] = $index; - if ($this->useGroups) { + if ($this->useGroups) { + foreach ($value as $index => &$data) { $data['_group'] = $this->getGroupCodeFromIndex($index); } } @@ -176,7 +175,7 @@ class Repeater extends FormWidgetBase if (is_array($loadValue)) { foreach ($loadValue as $index => $loadedValue) { - $loadedIndexes[] = array_get($loadedValue, '_index', $index); + $loadedIndexes[] = $index; $loadedGroups[] = array_get($loadedValue, '_group'); } } @@ -234,17 +233,12 @@ class Repeater extends FormWidgetBase */ protected function getLoadValueFromIndex($index) { - if (is_array($loadValue = $this->getLoadValue())) { - foreach ($loadValue as $_index => $data) { - if (array_get($data, '_index') == $index) { - return $data; - } - - if ($_index == $index) { - return $data; - } - } + $loadValue = $this->getLoadValue(); + if (!is_array($loadValue)) { + $loadValue = []; } + + return array_get($loadValue, $index, []); } //