mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #7434 from open-sausages/pulls/4.0/the-tree-needs-cutting
Fix refactor TreeMultiselectField to be clearable if nothing is selected
This commit is contained in:
commit
58cd83e4f7
@ -215,12 +215,10 @@ class TreeMultiselectField extends TreeDropdownField
|
||||
*/
|
||||
public function saveInto(DataObjectInterface $record)
|
||||
{
|
||||
// Detect whether this field has actually been updated
|
||||
if ($this->value !== 'unchanged') {
|
||||
$items = [];
|
||||
|
||||
$fieldName = $this->name;
|
||||
$saveDest = $record->$fieldName();
|
||||
|
||||
if (!$saveDest) {
|
||||
$recordClass = get_class($record);
|
||||
user_error(
|
||||
@ -230,11 +228,14 @@ class TreeMultiselectField extends TreeDropdownField
|
||||
);
|
||||
}
|
||||
|
||||
// Detect whether this field has actually been updated
|
||||
if ($this->value !== 'unchanged') {
|
||||
if (is_array($this->value)) {
|
||||
$items = $this->value;
|
||||
} elseif ($this->value) {
|
||||
$items = preg_split("/ *, */", trim($this->value));
|
||||
}
|
||||
}
|
||||
|
||||
// Allows you to modify the items on your object before save
|
||||
$funcName = "onChange$fieldName";
|
||||
@ -244,10 +245,8 @@ class TreeMultiselectField extends TreeDropdownField
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$saveDest->setByIDList($items);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes this field to the readonly field.
|
||||
|
Loading…
Reference in New Issue
Block a user