Support inline editing of many many extra fields.

This commit is contained in:
ajshort 2013-02-10 16:59:06 +11:00
parent 38bb120c88
commit 82cde164e9
3 changed files with 32 additions and 4 deletions

View File

@ -115,6 +115,7 @@ class GridFieldAddNewInlineButton implements GridField_HTMLProvider, GridField_S
}
public function handleSave(GridField $grid, DataObjectInterface $record) {
$list = $grid->getList();
$value = $grid->Value();
if(!isset($value[__CLASS__]) || !is_array($value[__CLASS__])) {
@ -130,12 +131,18 @@ class GridFieldAddNewInlineButton implements GridField_HTMLProvider, GridField_S
}
foreach($value[__CLASS__] as $fields) {
$item = new $class();
$item = new $class();
$extra = array();
if($list instanceof ManyManyList) {
$extra = array_intersect_key($fields, $list->getExtraFields());
}
$form->loadDataFrom($fields, Form::MERGE_CLEAR_MISSING);
$form->saveInto($item);
$grid->getList()->add($item);
$item->write();
$list->add($item, $extra);
}
}

View File

@ -50,6 +50,7 @@ class GridFieldEditableColumns extends GridFieldDataColumns implements
}
public function handleSave(GridField $grid, DataObjectInterface $record) {
$list = $grid->getList();
$value = $grid->Value();
if(!isset($value[__CLASS__]) || !is_array($value[__CLASS__])) {
@ -63,16 +64,23 @@ class GridFieldEditableColumns extends GridFieldDataColumns implements
continue;
}
$item = $grid->getList()->byID($id);
$item = $list->byID($id);
if(!$item || !$item->canEdit()) {
continue;
}
$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);
}
}
@ -113,7 +121,9 @@ class GridFieldEditableColumns extends GridFieldDataColumns implements
public function getFields(GridField $grid, DataObjectInterface $record) {
$cols = $this->getDisplayFields($grid);
$fields = new FieldList();
$class = $grid->getList()->dataClass();
$list = $grid->getList();
$class = $list->dataClass();
foreach($cols as $col => $info) {
$field = null;
@ -135,6 +145,14 @@ class GridFieldEditableColumns extends GridFieldDataColumns implements
}
}
if(!$field && $list instanceof ManyManyList) {
$extra = $list->getExtraFields();
if(array_key_exists($col, $extra)) {
$field = Object::create_from_string($extra[$col], $col)->scaffoldFormField();
}
}
if(!$field) {
if($obj = singleton($class)->dbObject($col)) {
$field = $obj->scaffoldFormField();

View File

@ -46,6 +46,9 @@ $grid->getConfig()->getComponentsByType('GridFieldEditableColumns')->setDisplayF
));
```
Editing data contained in `many_many_extraFields` is supported - just treat it as you would any
other field.
Multi Class Adding
------------------