Fix refactor TreeMultiselectField to be clearable if nothing is selected

This commit is contained in:
Christopher Joe 2017-10-05 14:58:27 +13:00
parent 168db412de
commit a1a8341929

View File

@ -215,12 +215,10 @@ class TreeMultiselectField extends TreeDropdownField
*/ */
public function saveInto(DataObjectInterface $record) public function saveInto(DataObjectInterface $record)
{ {
// Detect whether this field has actually been updated
if ($this->value !== 'unchanged') {
$items = []; $items = [];
$fieldName = $this->name; $fieldName = $this->name;
$saveDest = $record->$fieldName(); $saveDest = $record->$fieldName();
if (!$saveDest) { if (!$saveDest) {
$recordClass = get_class($record); $recordClass = get_class($record);
user_error( 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)) { 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 // Allows you to modify the items on your object before save
$funcName = "onChange$fieldName"; $funcName = "onChange$fieldName";
@ -244,10 +245,8 @@ class TreeMultiselectField extends TreeDropdownField
return; return;
} }
} }
$saveDest->setByIDList($items); $saveDest->setByIDList($items);
} }
}
/** /**
* Changes this field to the readonly field. * Changes this field to the readonly field.