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

[Solved] Limiting TreeMultiSelect


Go to End


2 Posts   1495 Views

Avatar
phillprice

Community Member, 6 Posts

16 April 2011 at 11:42pm

I have a working TreeMultiSelect, the sourceObject I've used is a subtype of page (Gallery).

However the field shows the whole SiteTree, rather than just these subtypes. Thankfully it ignores if you try to pick a normal page but it still bugs me.

Probably unrelated but Photograph is managed in ModelAdmin

class Photograph extends DataObject {

	...

	static $many_many = array(
		'Galleries' => 'Gallery'
	);
	
	...

	function getCMSFields() {
		$fields = parent::getCMSFields();
		$fields->addFieldToTab("Root.Galleries", new TreeMultiselectField('Galleries', 'Choose Galleries to show Photo', "Gallery"));
		return $fields;
	}

	...

}

class Gallery extends Page {

	...

	static $belongs_many_many = array(		
		'Photographs' => 'Photograph'
	);

}

class Gallery_Controller extends Page_Controller  {
		
	...

}

Avatar
Shane Garelja

Community Member, 18 Posts

16 April 2011 at 11:55pm

Hi Phill,

This is the correct behaviour when passing in a 'hierarchy' object as the 3rd parameter. It needs to display all types in order to generate the tree view.

If you wish to only see your Gallery page types then you can pass an array of key/values pairs as the 3rd param instead. This will mean that you have a flat list to select from as a hierarchy no longer exists. You could do this like so:

function getCMSFields() { 
	$fields = parent::getCMSFields(); 
	$galleryPages = DataObject::get('Gallery');
	$fields->addFieldToTab("Root.Galleries", new TreeMultiselectField('Galleries', 'Choose Galleries to show Photo', $galleryPages->map())); 
	return $fields; 
}