From d35747942113b1aabec88a6b6157a7f949190fda Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Mon, 26 Aug 2019 12:37:19 +1200 Subject: [PATCH] FIX: Let GridFieldEditableColumns edit relations via dot syntax This is a companion to https://github.com/silverstripe/silverstripe-framework/pull/9192 to provide the same functionality for inline editing in GridFields A valuable use of this is editing fields in the join-object of a many-many-through relation. --- src/GridFieldEditableColumns.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/GridFieldEditableColumns.php b/src/GridFieldEditableColumns.php index 6e6b192..55fa648 100644 --- a/src/GridFieldEditableColumns.php +++ b/src/GridFieldEditableColumns.php @@ -82,8 +82,7 @@ class GridFieldEditableColumns extends GridFieldDataColumns implements $field = clone $field; } else { $value = $grid->getDataFieldValue($record, $col); - $rel = (strpos($col, '.') === false); // field references a relation value - $field = ($rel) ? clone $fields->fieldByName($col) : new ReadonlyField($col); + $field = $fields->dataFieldByName($col); if (!$field) { throw new Exception("Could not find the field '$col'"); @@ -138,10 +137,11 @@ class GridFieldEditableColumns extends GridFieldDataColumns implements $extra = array(); - $form = $this->getForm($grid, $record); + $form = $this->getForm($grid, $item); $form->loadDataFrom($fields, Form::MERGE_CLEAR_MISSING); $form->saveInto($item); + // Check if we are also sorting these records if ($sortable) { $sortField = $sortable->getSortField(); @@ -154,7 +154,7 @@ class GridFieldEditableColumns extends GridFieldDataColumns implements $extra = array_intersect_key($form->getData(), (array) $list->getExtraFields()); } - $item->write(); + $item->write(false, false, false, true); $list->add($item, $extra); } }