mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX Allowing to save ListboxField and CheckboxSetField into custom relations (which don't return TRUE for has_many() or many_many())
This commit is contained in:
parent
79d420f941
commit
b43bdf3781
@ -181,15 +181,16 @@ class CheckboxSetField extends OptionsetField {
|
||||
* @param DataObject $record The record to save into
|
||||
*/
|
||||
function saveInto(DataObject $record) {
|
||||
$fieldname = $this->name ;
|
||||
if($fieldname && $record && ($record->has_many($fieldname) || $record->many_many($fieldname))) {
|
||||
$fieldname = $this->name;
|
||||
$relation = ($fieldname && $record && $record->hasMethod($fieldname)) ? $record->$fieldname() : null;
|
||||
if($fieldname && $record && $relation && $relation instanceof RelationList) {
|
||||
$idList = array();
|
||||
if($this->value) foreach($this->value as $id => $bool) {
|
||||
if($bool) {
|
||||
$idList[] = $id;
|
||||
}
|
||||
}
|
||||
$record->$fieldname()->setByIDList($idList);
|
||||
$relation->setByIDList($idList);
|
||||
} elseif($fieldname && $record) {
|
||||
if($this->value) {
|
||||
$this->value = str_replace(',', '{comma}', $this->value);
|
||||
|
@ -172,10 +172,11 @@ class ListboxField extends DropdownField {
|
||||
function saveInto(DataObject $record) {
|
||||
if($this->multiple) {
|
||||
$fieldname = $this->name;
|
||||
if($fieldname && $record && ($record->has_many($fieldname) || $record->many_many($fieldname))) {
|
||||
$relation = ($fieldname && $record && $record->hasMethod($fieldname)) ? $record->$fieldname() : null;
|
||||
if($fieldname && $record && $relation && $relation instanceof RelationList) {
|
||||
$idList = (is_array($this->value)) ? array_values($this->value) : array();
|
||||
if(!$record->ID) $record->write(); // record needs to have an ID in order to set relationships
|
||||
$record->$fieldname()->setByIDList($idList);
|
||||
$relation->setByIDList($idList);
|
||||
} elseif($fieldname && $record) {
|
||||
if($this->value) {
|
||||
$this->value = str_replace(',', '{comma}', $this->value);
|
||||
|
Loading…
Reference in New Issue
Block a user