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

Populating a "TreeMultiSelectField" with images from Assets Folder


Go to End


3 Posts   1812 Views

Avatar
LinseyM

Community Member, 99 Posts

27 October 2011 at 2:27am

Hi there,

In my CMS I want to have a TreeMultiSelectField type dropdown which lists all of the images in the Assets folder & subfolders (in the same way as when you go to add an image via the WYSIWYG editor).

The user should be able to select / check multiple images, which I would then use to display a slideshow of images within the site.

Can anyone point me in the right direction for this? I've tried a few things but its not working at all => I don't know if you can "call" assets in the same way as you call the site tree, e.g.:

public static $many_many = array(
	"ChoosePages" => "SiteTree"
); 

function getCMSFields() {
	$fields = parent::getCMSFields();
	$fields->addFieldToTab('Root.Content.PageList', new TreeMultiSelectField('ChoosePages', 'Select pages to list', 'SiteTree'), '');
	return $fields;
}

Many thanks,

Linsey

Avatar
hello_world

Community Member, 19 Posts

28 October 2011 at 12:47am

Edited: 28/10/2011 12:51am

Hi,

1) Change relationship in $many_many e.g.

public static $many_many = array(
   "MyImages" => "File"
); 

and /dev/build

2) In getCMSField


...
   $fields->addFieldToTab('Root.Content.PageList', new TreeMultiSelectField('MyImages', 'Select your images from list', 'File'), '');
   return $fields; 

Everything works fine but after save contnet you can not see which images will be selected.
I wrote about this in this post, but no answer.
http://www.silverstripe.org/customising-the-cms/show/18385

Avatar
LinseyM

Community Member, 99 Posts

28 October 2011 at 7:56am

Thanks so much for your help - I'd already tried "File" in the CMS Fields section, but I had left it as "site tree" in the many>many relationship - what an idiot!

Just wanted to let you know though, that the boxes I check do remain checked after I save / save & publish / exit and return to the page.

Thanks again, L x