Jump to:

5452 Posts in 1673 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Populating a "TreeMultiSelectField" with images from Assets Folder

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

Page: 1
Go to End
Author Topic: 620 Views
  • LinseyM
    Avatar
    Community Member
    99 Posts

    Populating a "TreeMultiSelectField" with images from Assets Folder Link to this post

    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

  • hello_world
    Avatar
    Community Member
    16 Posts

    Re: Populating a "TreeMultiSelectField" with images from Assets Folder Link to this post

    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

  • LinseyM
    Avatar
    Community Member
    99 Posts

    Re: Populating a "TreeMultiSelectField" with images from Assets Folder Link to this post

    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

    620 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.