silverstripe-gridfield-betterbuttons
silverstripe-gridfield-betterbuttons copied to clipboard
ManyMany[FIELD_NAME] checkbox set field can't be saved
trafficstars
$detailFormFields->push(CheckboxSetField::create('ManyMany[AvailableMonths]', 'Available Months', $monthSource))
When you have pushed a many many extra field to the GridField detail form and hit the Save and close button it triggers an error
protected function saveAndRedirect($data, $form, $redirectLink) {
$new_record = $this->owner->record->ID == 0;
$controller = Controller::curr();
$list = $this->owner->gridField->getList();
if($list instanceof ManyManyList) {
// Data is escaped in ManyManyList->add()
$extraData = (isset($data['ManyMany'])) ? $data['ManyMany'] : null;
} else {
$extraData = null;
}
if(!$this->owner->record->canEdit()) {
return $controller->httpError(403);
}
try {
$form->saveInto($this->owner->record);
$this->owner->record->write();
$list->add($this->owner->record, $extraData);
}
........
}
Issue is with manipulating the $extraData. The GridFieldDetailForm_ItemRequest get that data by customising the $data['ManyMany'] but betterbuttons is not like that.
I think try{} can be done like (code snippet from GridFieldDetailForm_ItemRequest::doSave()):
$form->saveInto($this->record);
$this->record->write();
$extraData = $this->getExtraSavedData($this->record, $list);
$list->add($this->record, $extraData);
It'll be starting point to fix the issue.
Hi,
I've create an PR https://github.com/unclecheese/silverstripe-gridfield-betterbuttons/pull/165 for this issue. Please have a look on that when possible
Thanks