Strip indexes from repeater data sets

This commit is contained in:
Samuel Georges 2017-04-26 08:10:45 +10:00
parent cc17b679f1
commit 6a6378a24d
1 changed files with 9 additions and 15 deletions

View File

@ -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, []);
}
//