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
This commit is contained in:
Ingo Schommer 2010-02-23 00:40:58 +00:00 committed by Sam Minnee
parent 923061fa07
commit 02c188633c

View File

@ -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);
}
}