mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Fix refactor TreeMultiselectField to be clearable if nothing is selected
This commit is contained in:
parent
168db412de
commit
a1a8341929
@ -215,38 +215,37 @@ class TreeMultiselectField extends TreeDropdownField
|
|||||||
*/
|
*/
|
||||||
public function saveInto(DataObjectInterface $record)
|
public function saveInto(DataObjectInterface $record)
|
||||||
{
|
{
|
||||||
|
$items = [];
|
||||||
|
$fieldName = $this->name;
|
||||||
|
$saveDest = $record->$fieldName();
|
||||||
|
|
||||||
|
if (!$saveDest) {
|
||||||
|
$recordClass = get_class($record);
|
||||||
|
user_error(
|
||||||
|
"TreeMultiselectField::saveInto() Field '$fieldName' not found on"
|
||||||
|
. " {$recordClass}.{$record->ID}",
|
||||||
|
E_USER_ERROR
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Detect whether this field has actually been updated
|
// Detect whether this field has actually been updated
|
||||||
if ($this->value !== 'unchanged') {
|
if ($this->value !== 'unchanged') {
|
||||||
$items = [];
|
|
||||||
|
|
||||||
$fieldName = $this->name;
|
|
||||||
$saveDest = $record->$fieldName();
|
|
||||||
if (!$saveDest) {
|
|
||||||
$recordClass = get_class($record);
|
|
||||||
user_error(
|
|
||||||
"TreeMultiselectField::saveInto() Field '$fieldName' not found on"
|
|
||||||
. " {$recordClass}.{$record->ID}",
|
|
||||||
E_USER_ERROR
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_array($this->value)) {
|
if (is_array($this->value)) {
|
||||||
$items = $this->value;
|
$items = $this->value;
|
||||||
} elseif ($this->value) {
|
} elseif ($this->value) {
|
||||||
$items = preg_split("/ *, */", trim($this->value));
|
$items = preg_split("/ *, */", trim($this->value));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allows you to modify the items on your object before save
|
|
||||||
$funcName = "onChange$fieldName";
|
|
||||||
if ($record->hasMethod($funcName)) {
|
|
||||||
$result = $record->$funcName($items);
|
|
||||||
if (!$result) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$saveDest->setByIDList($items);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Allows you to modify the items on your object before save
|
||||||
|
$funcName = "onChange$fieldName";
|
||||||
|
if ($record->hasMethod($funcName)) {
|
||||||
|
$result = $record->$funcName($items);
|
||||||
|
if (!$result) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$saveDest->setByIDList($items);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user