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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

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

TreeDropdownField return subtree of hierarchy


Go to End


2 Posts   1956 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');