I am managing a DataObject
via ModelAdmin
and I have added a custom button because I want to do a custom action when adding the item.
class InventoryAdmin extends ModelAdmin {
public function getEditForm($id = null, $fields = null) {
$form = parent::getEditForm($id, $fields);
$listField = $form->Fields()->fieldByName($this->modelClass);
if ($gridField = $listField->getConfig()->getComponentByType('GridFieldDetailForm'))
$gridField->setItemRequestClass('InventoryFieldDetailForm_ItemRequest');
return $form;
}
}
class InventoryFieldDetailForm_ItemRequest extends GridFieldDetailForm_ItemRequest {
private static $allowed_actions = array (
'edit',
'view',
'ItemEditForm'
);
public function ItemEditForm() {
$form = parent::ItemEditForm();
$formActions = $form->Actions();
$formActions->removeByName('action_doSave');
if ($actions = $this->record->getCMSActions()) {
foreach ($actions as $action) {
$formActions->push($action);
}
}
return $form;
}
public function doAddInventoryItem($data, $form) {
return Controller::curr()->redirect($this->getToplevelController()->Link());
}
}
This works however on submission the CMS goes back to the parent and it's offset by about 15 px. The main issue is that the CMS UI becomes unresponsive from then on until a refresh.
What should I be redirecting to to get to the parent ModelAdmin
?