From 02c188633cc7e5a71279d7b6bdf6cd445e864709 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 23 Feb 2010 00:40:58 +0000 Subject: [PATCH] BUGFIX Fixed TreeMultiselectField->Field() to respect settings, and give them priority over existing relations through getItems(). This is used in MemberTableField to set default groups for 'add member' popups. (from r98879) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@99647 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- forms/TreeMultiselectField.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/forms/TreeMultiselectField.php b/forms/TreeMultiselectField.php index 71f2897a2..6150e7e68 100755 --- a/forms/TreeMultiselectField.php +++ b/forms/TreeMultiselectField.php @@ -55,8 +55,19 @@ class TreeMultiselectField extends TreeDropdownField { Requirements::css(SAPPHIRE_DIR . '/javascript/tree/tree.css'); Requirements::css(SAPPHIRE_DIR . '/css/TreeDropdownField.css'); - $items = $this->getItems(); - if($items) { + // Any field values have priority over the relation getters + if($this->value) { + $items = new DataObjectSet(); + $ids = explode(',', $this->value); + foreach($ids as $id) { + $item = DataObject::get_by_id($this->sourceObject, $id); + if($item) $items->push($item); + } + } else { + $items = $this->getItems(); + } + + if($items && $items->Count()) { foreach($items as $item) { $titleArray[] =$item->Title; $idArray[] = $item->ID; @@ -65,7 +76,7 @@ class TreeMultiselectField extends TreeDropdownField { $itemList = implode(", ", $titleArray); $value = implode(",", $idArray); } - } + } $id = $this->id(); @@ -100,6 +111,7 @@ HTML; return; } } + $saveDest->setByIDList($items); } }