Fix inline adding and editing with no model class defined

This commit is contained in:
Andrew Short 2013-06-22 21:38:29 +10:00
parent 7d63584d42
commit 159b9bbd5c
2 changed files with 12 additions and 10 deletions

View File

@ -57,17 +57,16 @@ class GridFieldAddNewInlineButton implements GridField_HTMLProvider, GridField_S
}
public function getHTMLFragments($grid) {
$class = $grid->getModelClass();
if($grid->getList() && !singleton($grid->getModelClass())->canCreate()) {
return array();
}
$fragment = $this->getFragment();
if(!$editable = $grid->getConfig()->getComponentByType('GridFieldEditableColumns')) {
throw new Exception('Inline adding requires the editable columns component');
}
if(!singleton($class)->canCreate()) {
return false;
}
Requirements::javascript(THIRDPARTY_DIR . '/javascript-templates/tmpl.js');
GridFieldExtensions::include_requirements();
@ -82,12 +81,15 @@ class GridFieldAddNewInlineButton implements GridField_HTMLProvider, GridField_S
}
private function getRowTemplate(GridField $grid, GridFieldEditableColumns $editable) {
$class = $grid->getModelClass();
$columns = new ArrayList();
$handled = array_keys($editable->getDisplayFields($grid));
$record = new $class();
if($grid->getList()) {
$record = Object::create($grid->getModelClass());
} else {
$record = null;
}
$fields = $editable->getFields($grid, $record);
foreach($grid->getColumns() as $column) {

View File

@ -123,7 +123,7 @@ class GridFieldEditableColumns extends GridFieldDataColumns implements
$fields = new FieldList();
$list = $grid->getList();
$class = $list->dataClass();
$class = $list ? $list->dataClass() : null;
foreach($cols as $col => $info) {
$field = null;
@ -154,7 +154,7 @@ class GridFieldEditableColumns extends GridFieldDataColumns implements
}
if(!$field) {
if($obj = singleton($class)->dbObject($col)) {
if($class && $obj = singleton($class)->dbObject($col)) {
$field = $obj->scaffoldFormField();
} else {
$field = new ReadonlyField($col);