Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Adding a TreeMultiselectField to a page type

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

Page: 1
Go to End
Author Topic: 1964 Views
  • mccarville
    Avatar
    Community Member
    32 Posts

    Adding a TreeMultiselectField to a page type Link to this post

    Hi everyone!

    I am pretty new to SS and I have to say I LOVE IT!!!

    I would like to create a page type that includes a TreeMultiselectField where a user could select multiple options from an expandable tree type menu while editing that page type in the admin section.

    Does anyone have an example of a class that can build and populate(with options I could define) the menu, and then add it into Root.admin.main so that the end user can use the tool??

    I would really appreciate any help you have to offer...

  • UncleCheese
    Avatar
    4085 Posts

    Re: Adding a TreeMultiselectField to a page type Link to this post

    You can run getChildrenAsUL() on any object to recursively build out its children. For instance, the menu on the left in the Site Content view of Silverstripe runs singleton('SiteTree')->getChildrenAsUL() (that is, essentially, every page that has been created). One of the arguments it takes is the "template" for the LI... so you can put special classes or hooks in there. I think that's in DataObject.php for reference. Might just look it up in the docs.

  • mccarville
    Avatar
    Community Member
    32 Posts

    Re: Adding a TreeMultiselectField to a page type Link to this post

    What you are saying making alot of sense, but to be honest it is a little over my head.

    I work for a school in New Jersey, US, and I am trying to develope a system for "online lesson planning". The one request I keep getting is for the teachers to be able to select the applicable "standards" from a list.

    The "standards" are dictated by the state and are formated like:

    1 - math
    1.1 - general
    1.1.1 - addition
    1.1.2 - subtraction

    Ideally there would be a check box or some method of "adding" for each speficic standard.

    Is this reasonable?

    ___________________________________________________________

    In Tutorial 2 it shows you how to dispaly the children of another section of the site.

    Can you use a similiar technique in the .php files in the 'code' folder to call the children of another area of the site?

    ::Hope that makes some sort of sense::

  • UncleCheese
    Avatar
    4085 Posts

    Re: Adding a TreeMultiselectField to a page type Link to this post

    Okay. What is the source of the whole standards hierarchy? Is it static? Or is this stored dynamically in the database?

  • UncleCheese
    Avatar
    4085 Posts

    Re: Adding a TreeMultiselectField to a page type Link to this post

    Actually, if my 15 credits of a masters degree in education serves me right, then you're probably looking at a population of standards that rarely changes. Let's assume that you have added all the standards, in order, to the Standards table.

    /mysite/code/Standard.php

    class Standard extends DataObject
    {
    static $db = array ('Name' => 'Varchar(50)','Number' => 'Varchar(10)');
    static $belongs_many_many = array ('Lesson');

    }

    /mysite/code/Lesson.php

    class Lesson extends Page
    {
    static $many_many = array ('Standards' => 'Standard');

    public function getCMSFields()
    {
    $f = parent::getCMSFields();
    $f->addFieldToTab("Root.Content.Standards",new CheckboxSetField('Standards','Standards (check all that apply)', DataObject::get("Standard")->toDropdownMap()));
    }
    }

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