mirror of
https://github.com/symbiote/silverstripe-gridfieldextensions.git
synced 2024-10-22 17:05:39 +02:00
Merge pull request #393 from creative-commoners/pulls/4/nested-gridfield
FIX Make child responsible for its own nested gridfield
This commit is contained in:
commit
4501565b79
@ -33,18 +33,9 @@ class GridFieldNestedFormItemRequest extends GridFieldDetailForm_ItemRequest
|
|||||||
{
|
{
|
||||||
return Controller::join_links($this->component->Link($this->record->ID), $action);
|
return Controller::join_links($this->component->Link($this->record->ID), $action);
|
||||||
}
|
}
|
||||||
|
|
||||||
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,11 +92,19 @@ 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);
|
||||||
|
|
||||||
$title = _t(get_class($this->record).'.'.strtoupper($relationName), ' ');
|
$title = _t(get_class($this->record).'.'.strtoupper($relationName), ' ');
|
||||||
|
|
||||||
$fields = new FieldList(
|
$fields = new FieldList(
|
||||||
$gridField = new GridField(
|
$gridField = new GridField(
|
||||||
sprintf(
|
sprintf(
|
||||||
@ -133,13 +136,13 @@ class GridFieldNestedFormItemRequest extends GridFieldDetailForm_ItemRequest
|
|||||||
$this->record->extend('updateNestedForm', $form);
|
$this->record->extend('updateNestedForm', $form);
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Breadcrumbs($unlinked = false)
|
public function Breadcrumbs($unlinked = false)
|
||||||
{
|
{
|
||||||
if (!$this->popupController->hasMethod('Breadcrumbs')) {
|
if (!$this->popupController->hasMethod('Breadcrumbs')) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var ArrayList $items */
|
/** @var ArrayList $items */
|
||||||
$items = $this->popupController->Breadcrumbs($unlinked);
|
$items = $this->popupController->Breadcrumbs($unlinked);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user