Skip to content

Commit

Permalink
BUGFIX Fixed TreeMultiselectField->Field() to respect settings, and g…
Browse files Browse the repository at this point in the history
…ive them priority over existing relations through getItems(). This is used in MemberTableField to set default groups for 'add member' popups.

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@98879 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information
chillu committed Feb 12, 2010
1 parent e6aa5b8 commit e26158c
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions forms/TreeMultiselectField.php
Expand Up @@ -40,8 +40,19 @@ function Field() {
Requirements::javascript(SAPPHIRE_DIR . '/javascript/LeftAndMain.js');
Requirements::javascript(SAPPHIRE_DIR . "/javascript/TreeSelectorField.js");

$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;
Expand All @@ -50,7 +61,7 @@ function Field() {
$itemList = implode(", ", $titleArray);
$value = implode(",", $idArray);
}
}
}

$id = $this->id();

Expand Down Expand Up @@ -85,6 +96,7 @@ function saveInto(DataObject $record) {
return;
}
}

$saveDest->setByIDList($items);
}
}
Expand Down

0 comments on commit e26158c

Please sign in to comment.