mirror of
https://github.com/symbiote/silverstripe-gridfieldextensions.git
synced 2024-10-22 17:05:39 +02:00
Merge pull request #294 from sminnee/allow-inline-dot-syntax
FIX: Let GridFieldEditableColumns edit relations via dot syntax
This commit is contained in:
commit
2fc085bbd0
@ -13,6 +13,7 @@ use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\ORM\DataObjectInterface;
|
||||
use SilverStripe\ORM\FieldType\DBField;
|
||||
use SilverStripe\ORM\ManyManyList;
|
||||
use SilverStripe\ORM\ManyManyThroughList;
|
||||
use SilverStripe\View\ArrayData;
|
||||
use SilverStripe\View\Requirements;
|
||||
use Exception;
|
||||
@ -189,9 +190,15 @@ class GridFieldAddNewInlineButton implements GridField_HTMLProvider, GridField_S
|
||||
foreach ($value[self::POST_KEY] as $fields) {
|
||||
/** @var DataObject $item */
|
||||
$item = $class::create();
|
||||
|
||||
// Add the item before the form is loaded so that the join-object is available
|
||||
if ($list instanceof ManyManyThroughList) {
|
||||
$list->add($item);
|
||||
}
|
||||
|
||||
$extra = array();
|
||||
|
||||
$form = $editable->getForm($grid, $record);
|
||||
$form = $editable->getForm($grid, $item);
|
||||
$form->loadDataFrom($fields, Form::MERGE_CLEAR_MISSING);
|
||||
$form->saveInto($item);
|
||||
|
||||
@ -205,8 +212,12 @@ class GridFieldAddNewInlineButton implements GridField_HTMLProvider, GridField_S
|
||||
$extra = array_intersect_key($form->getData(), (array) $list->getExtraFields());
|
||||
}
|
||||
|
||||
$item->write();
|
||||
$list->add($item, $extra);
|
||||
$item->write(false, false, false, true);
|
||||
|
||||
// Add non-through lists after the write. many_many_extraFields are added there too
|
||||
if (!($list instanceof ManyManyThroughList)) {
|
||||
$list->add($item, $extra);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user