mirror of
https://github.com/symbiote/silverstripe-gridfieldextensions.git
synced 2024-10-22 17:05:39 +02:00
Fix inline adding and editing with no model class defined
This commit is contained in:
parent
7d63584d42
commit
159b9bbd5c
@ -57,17 +57,16 @@ class GridFieldAddNewInlineButton implements GridField_HTMLProvider, GridField_S
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getHTMLFragments($grid) {
|
public function getHTMLFragments($grid) {
|
||||||
$class = $grid->getModelClass();
|
if($grid->getList() && !singleton($grid->getModelClass())->canCreate()) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
$fragment = $this->getFragment();
|
$fragment = $this->getFragment();
|
||||||
|
|
||||||
if(!$editable = $grid->getConfig()->getComponentByType('GridFieldEditableColumns')) {
|
if(!$editable = $grid->getConfig()->getComponentByType('GridFieldEditableColumns')) {
|
||||||
throw new Exception('Inline adding requires the editable columns component');
|
throw new Exception('Inline adding requires the editable columns component');
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!singleton($class)->canCreate()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Requirements::javascript(THIRDPARTY_DIR . '/javascript-templates/tmpl.js');
|
Requirements::javascript(THIRDPARTY_DIR . '/javascript-templates/tmpl.js');
|
||||||
GridFieldExtensions::include_requirements();
|
GridFieldExtensions::include_requirements();
|
||||||
|
|
||||||
@ -82,12 +81,15 @@ class GridFieldAddNewInlineButton implements GridField_HTMLProvider, GridField_S
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function getRowTemplate(GridField $grid, GridFieldEditableColumns $editable) {
|
private function getRowTemplate(GridField $grid, GridFieldEditableColumns $editable) {
|
||||||
$class = $grid->getModelClass();
|
|
||||||
|
|
||||||
$columns = new ArrayList();
|
$columns = new ArrayList();
|
||||||
$handled = array_keys($editable->getDisplayFields($grid));
|
$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);
|
$fields = $editable->getFields($grid, $record);
|
||||||
|
|
||||||
foreach($grid->getColumns() as $column) {
|
foreach($grid->getColumns() as $column) {
|
||||||
|
@ -123,7 +123,7 @@ class GridFieldEditableColumns extends GridFieldDataColumns implements
|
|||||||
$fields = new FieldList();
|
$fields = new FieldList();
|
||||||
|
|
||||||
$list = $grid->getList();
|
$list = $grid->getList();
|
||||||
$class = $list->dataClass();
|
$class = $list ? $list->dataClass() : null;
|
||||||
|
|
||||||
foreach($cols as $col => $info) {
|
foreach($cols as $col => $info) {
|
||||||
$field = null;
|
$field = null;
|
||||||
@ -154,7 +154,7 @@ class GridFieldEditableColumns extends GridFieldDataColumns implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!$field) {
|
if(!$field) {
|
||||||
if($obj = singleton($class)->dbObject($col)) {
|
if($class && $obj = singleton($class)->dbObject($col)) {
|
||||||
$field = $obj->scaffoldFormField();
|
$field = $obj->scaffoldFormField();
|
||||||
} else {
|
} else {
|
||||||
$field = new ReadonlyField($col);
|
$field = new ReadonlyField($col);
|
||||||
|
Loading…
Reference in New Issue
Block a user