Jump to:

5554 Posts in 1742 Topics by 1227 members

Customising the CMS

SilverStripe Forums » Customising the CMS » [Solved] Limiting TreeMultiSelect

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

Page: 1
Go to End
Author Topic: 707 Views
  • phillprice
    Avatar
    Community Member
    6 Posts

    [Solved] Limiting TreeMultiSelect Link to this post

    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 {
          
       ...

    }

  • Shane Garelja
    Avatar
    Community Member
    18 Posts

    Re: [Solved] Limiting TreeMultiSelect Link to this post

    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;
    }

    707 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.