Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

TreeDropdownField return subtree of hierarchy


Go to End


2 Posts   1365 Views

Avatar
sean.smorris

Community Member, 1 Post

28 December 2010 at 6:37am

I noticed this question from a post in 2009 that was never answered.

I wanted to filter the TreeDropdownfield to only return a subtree of the whole tree and can't seem to pull it off.

SiteTree
--- SubTree1
------- Subtree1.1
------- Subtree1.2
--- SubTree2
------- Subtree2.1
------- Subtree2.2

Depending on where the users is navigating I will only want to show Subtree1.2 or Subtree2.2 or both.

I appreciate any help here.

Thanks,

Sean

Avatar
bummzack

Community Member, 904 Posts

9 September 2015 at 9:00pm

I realize this reviving a very old thread, but I've been looking for an answer to this problem as well and this seems to be the only topic that shows up on a Google search.

The solution is to set setTreeBaseID on the TreeDropdownfield.
Example:

$select = TreeMultiselectField::create('Related', 'Related pages', 'SiteTree', 'ID', 'Title');
$select->setTreeBaseID($parent->ID);

Another thing to note: Even if you want to target specific subclasses of SiteTree, you have to use SiteTree as the source-object parameter. Something like this won't work, even if all your sub-pages are of type SubPage (for it to work, all the parent pages would have to be of that page-type as well):

//                                                           ↓ NOPE!
TreeMultiselectField::create('Related', 'Related pages', 'SubPage', 'ID', 'Title');