Skip to content

Commit

Permalink
FIX: Let GridFieldEditableColumns edit relations via dot syntax
Browse files Browse the repository at this point in the history
This is a companion to silverstripe/silverstripe-framework#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.
  • Loading branch information
Sam Minnee committed Aug 26, 2019
1 parent 668b297 commit d357479
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/GridFieldEditableColumns.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ public function getColumnContent($grid, $record, $col)
$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'");
Expand Down Expand Up @@ -138,10 +137,11 @@ public function handleSave(GridField $grid, DataObjectInterface $record)

$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();
Expand All @@ -154,7 +154,7 @@ public function handleSave(GridField $grid, DataObjectInterface $record)
$extra = array_intersect_key($form->getData(), (array) $list->getExtraFields());
}

$item->write();
$item->write(false, false, false, true);
$list->add($item, $extra);
}
}
Expand Down

0 comments on commit d357479

Please sign in to comment.