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.

Customising the CMS /

TreeDropdownField not displaying anything on SilverStripe 3.0


Go to End
Reply


2 Posts   681 Views

Avatar
mrsteveheyes

Community Member, 15 Posts

13 July 2012 at 9:35pm

Hi there.

I am wanting to do related pages on my site. How I did this on 2.4 was use a related SiteTree object and TreeDropdownField. The code I'm using is bellow:

 public static $has_one = array(

        'Feature1Page'         => 'SiteTree',
    );

     public function getCMSFields() {
        $fields = parent::getCMSFields();

        $fields->addFieldToTab('Root.Main', new TreeDropdownField('Feature1PageID', 'Feature 1 Link', 'SiteTree'));

        $return $fields;
     }

The dropdown menu shows in the CMS, but when I go to select something and press the arrow down button nothing is shown. Am I missing something or done something wrong? Or is this a bug that needs fixing in 3.0?

Cheers,
Steve

Avatar
vegetav

Community Member, 23 Posts

7 August 2012 at 11:42pm

That looks like it should work to me. I am doing using the TreeDropdownField in a DatObject in 3.0.1 in the same way thaty ou are and it works fine for me.

Here is my code for reference...

class Feature extends DataObject {
	static $db = array (
		'Title' => 'Text',
	);
    
	static $has_one = array (
        'HomePage' => 'HomePage',
        'LinkPage' => 'SiteTree',
	);

    public static $summary_fields = array(
        'Title' => 'Title',
    ); 
    
    public function getCMSFields() {
        return new FieldList(
            new TextField('Title'),
            new TreeDropdownField('LinkPageID', 'Link', 'SiteTree')
        );
    }
}

And in my template...

<% loop Features %>
	<a href="$LinkPage.Link" id="link$ID">$Title</a>
<% end_loop %>