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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Customising the CMS /

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

Can only display one TreeDropdownField ?

Go to End

3 Posts   1701 Views


Community Member, 165 Posts

6 January 2010 at 6:56pm

Edited: 06/01/2010 7:11pm

I'm trying to get a "featured content" thing happening.
There's supposed to be a bit of text, a heading, an associated image and two page id's.
One would be for the page where the content will be displayed and the other would be a page that the user would be taken to if they click on the associated image.

I've read that the TreeDropdownField doesn't work in widgets, so I've created a page where users can input the featured content and say on which pages they want it.

So far it looks like this:

class FeaturedContent extends DataObject{

    static $db = array(
        "FeaturedContentTitle" => "Varchar(40)",
        "FeaturedContentText" => "Text",
        "FeaturedContentDisplay" => "Boolean"
    static $has_one = array(
        "FeaturedContentHostPage" => "SiteTree",
        "FeaturedContentLink" => "SiteTree",
        "FeaturedContentImage" => "Image"
    function getCMSFields_forPopup() {

        $fields = new FieldSet();
        $fields->push(new TextField("FeaturedContentTitle", "Title"));
        $fields->push(new TextareaField("FeaturedContentText", "Text"));
        $fields->push(new CheckboxField("FeaturedContentDisplay", "Display this content?"));
        $fields->push(new TreeDropdownField("FeaturedContentHostPageID", "Display On", 'SiteTree'));
        $fields->push(new TreeDropdownField("FeaturedContentLinkID", 'Linkto', 'SiteTree'));
        $fields->push(new ImageField("FeaturedContentImage", "Associated Image"));
        return $fields;

class ManageFeaturedContentPage extends Page{

    function getCMSFields() {

        $fields = parent::getCMSFields();

    	$FeaturedContent = Object::create("FeaturedContent");

        $TableField = new ComplexTableField(
            $controller = $this,
    		$name = "lstFeaturedContent",
            $sourceClass = $FeaturedContent->class,
    	   	$fieldList = array(
                'FeaturedContentTitle' => 'Content Title',
                'FeaturedContentText' => 'Content'
            $functionForPopupFields = "getCMSFields_forPopup",
            $sourceFilter = "",
            $sourceSort = "FeaturedContentTitle"


        $fields->addFieldToTab( 'Root.Content.Main', $TableField );
        $fields->removeFieldFromTab('Root.Content.Main', 'Content');
        return $fields;

Now, the odd bit is that the image works fine and ONE of the TreeDropdownFields works fine, but it only ever displays one. I can never get them both displayed and working. Sometimes it's one, sometimes it's the other (can't figure out the rule behind this) and whatever column is not displayed automatically gets assigned the page id of the manage featured content page.

I've tried using different browsers and tried it on versions 2.3.4 and 2.3.2 and it doesn't work on either of them.

Can anyone tell me what I am doing wrong?


Community Member, 165 Posts

7 January 2010 at 2:17am

I've stumbled upon a workaround but it's a real kludge and I have no idea why it's working, so it's probably going to fail at the worst possible time :P

Anyway, I added a third "SiteTree" and now it's actually working.

    static $has_one = array(
        "FeaturedContentImage" => "Image",
        "FeaturedContentLink" => "SiteTree",
        "FeaturedContentHost" => "SiteTree",
        "FeaturedContentLinkToPage" => "SiteTree"

FeaturedContentLink still doesn't display on the popup, but takes on the page id of the page on which I have the table. It's therefore, always set to "23". I don't know why.

And FeaturedContentLinkToPage displays and receives the selected page's ID. That's all correct and the way it should be.

Can someone tell me why this is happening? I've reinstalled SS and the problem is still there. It's not a browser or a version thing either. Weird.


Community Member, 165 Posts

10 January 2010 at 11:47am

*bouncing* this in case somebody has had a similar problem before.

Since my last post, I've come up with a better work-around (eg: rename the TreeDropdownField in the popup to some arbitrary name and then manually assign the values to the database fields in the onBeforeWrite function), but it really worries me that the TreeDropdownField works in such a haphazard way. I'm sure I must be doing something wrong, but what?