From 2f0e17ee586716ebed8d575b8d6cab4ecd36aa20 Mon Sep 17 00:00:00 2001 From: Martijn Date: Fri, 15 Feb 2013 21:05:48 +0100 Subject: [PATCH] Update code/GridFieldEditableColumns.php Don't save ChildItem Values when a Column exists in many_many_extraFields Get values from many_many_extraFields instead of ChildItem --- code/GridFieldEditableColumns.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/code/GridFieldEditableColumns.php b/code/GridFieldEditableColumns.php index fd2b5ed..09cd805 100644 --- a/code/GridFieldEditableColumns.php +++ b/code/GridFieldEditableColumns.php @@ -25,8 +25,14 @@ class GridFieldEditableColumns extends GridFieldDataColumns implements } $fields = $this->getForm($grid, $record)->Fields(); - $value = $grid->getDataFieldValue($record, $col); $field = clone $fields->fieldByName($col); + $list = $grid->getList(); + $extraData = array(); + if($list instanceof ManyManyList) { + $extraData = $list->getExtraData($grid->getName(), $record->ID); + } + + $value = isset($extraData[$col]) ? $extraData[$col] : $grid->getDataFieldValue($record, $col); if(!$field) { throw new Exception("Could not find the field '$col'"); @@ -71,16 +77,16 @@ class GridFieldEditableColumns extends GridFieldDataColumns implements } $extra = array(); - - if($list instanceof ManyManyList) { - $extra = array_intersect_key($fields, $list->getExtraFields()); - } - + $form->loadDataFrom($fields, Form::MERGE_CLEAR_MISSING); $form->saveInto($item); - - $item->write(); - $list->add($item, $extra); + + if($list instanceof ManyManyList) { + $extra = array_intersect_key($fields, $list->getExtraFields()); + $list->add($item, $extra); + } else { + $item->write(); + } } }