mirror of
https://github.com/symbiote/silverstripe-gridfieldextensions.git
synced 2024-10-22 17:05:39 +02:00
FIX Make child responsible for its own nested gridfield
This commit is contained in:
parent
678ec6f7e1
commit
945ea7fc0b
@ -36,15 +36,6 @@ class GridFieldNestedFormItemRequest extends GridFieldDetailForm_ItemRequest
|
|||||||
|
|
||||||
public function ItemEditForm()
|
public function ItemEditForm()
|
||||||
{
|
{
|
||||||
$config = new GridFieldConfig_RecordEditor();
|
|
||||||
/** @var GridFieldDetailForm */
|
|
||||||
$detailForm = $config->getComponentByType(GridFieldDetailForm::class);
|
|
||||||
$detailForm->setItemEditFormCallback(function (Form $form, $itemRequest) {
|
|
||||||
$breadcrumbs = $itemRequest->Breadcrumbs(false);
|
|
||||||
if ($breadcrumbs && $breadcrumbs->exists()) {
|
|
||||||
$form->Backlink = $breadcrumbs->first()->Link;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
$relationName = $this->component->getRelationName();
|
$relationName = $this->component->getRelationName();
|
||||||
$list = $this->record->$relationName();
|
$list = $this->record->$relationName();
|
||||||
if ($relationName == 'Children' && $this->record->hasExtension(Hierarchy::class)) {
|
if ($relationName == 'Children' && $this->record->hasExtension(Hierarchy::class)) {
|
||||||
@ -55,10 +46,14 @@ class GridFieldNestedFormItemRequest extends GridFieldDetailForm_ItemRequest
|
|||||||
->forForeignID($this->record->ID);
|
->forForeignID($this->record->ID);
|
||||||
}
|
}
|
||||||
$relationClass = $list->dataClass();
|
$relationClass = $list->dataClass();
|
||||||
|
$singleton = singleton($relationClass);
|
||||||
|
|
||||||
if ($this->record->hasMethod('getNestedConfig')) {
|
$config = null;
|
||||||
$config = $this->record->getNestedConfig();
|
if ($singleton->hasMethod('getNestedConfig')) {
|
||||||
} else {
|
$config = $singleton->getNestedConfig(get_class($this->record), $relationName);
|
||||||
|
}
|
||||||
|
if (!$config) {
|
||||||
|
$config = new GridFieldConfig_RecordEditor();
|
||||||
$canEdit = $this->record->canEdit();
|
$canEdit = $this->record->canEdit();
|
||||||
if (!$canEdit) {
|
if (!$canEdit) {
|
||||||
$config->removeComponentsByType(GridFieldAddNewButton::class);
|
$config->removeComponentsByType(GridFieldAddNewButton::class);
|
||||||
@ -97,6 +92,14 @@ class GridFieldNestedFormItemRequest extends GridFieldDetailForm_ItemRequest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/** @var GridFieldDetailForm */
|
||||||
|
$detailForm = $config->getComponentByType(GridFieldDetailForm::class);
|
||||||
|
$detailForm->setItemEditFormCallback(function (Form $form, $itemRequest) {
|
||||||
|
$breadcrumbs = $itemRequest->Breadcrumbs(false);
|
||||||
|
if ($breadcrumbs && $breadcrumbs->exists()) {
|
||||||
|
$form->Backlink = $breadcrumbs->first()->Link;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$this->record->invokeWithExtensions('updateNestedConfig', $config);
|
$this->record->invokeWithExtensions('updateNestedConfig', $config);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user