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 doesn't save selection - SS2.4


Reply

3 Posts   1138 Views

Avatar
Tama

13 July 2010 at 1:14pm Community Member, 130 Posts

Howdy

I have added the following code to create a selectable drop down tree of CMS pages for one of my page types:

class ArchivePage extends Page {

   static $db = array(
         
   );

   static $has_one = array(
      'ArchivePageID' => 'SiteTree',
   );

   function getCMSFields(){
      $tree = new TreeDropdownField('ArchivePageID', 'Choose a Parent page to display an archive of the Child pages', 'SiteTree');
      $fields = parent::getCMSFields();
      $fields->addFieldToTab('Root.Content.Main', $tree, 'Content');
      
      return $fields;
   }

}

This displays a dropdown selection of all of the pages in the website but when I select a page and click "Save" the box resets to just reading "(Choose)".

I'm sure I'm just making a simple mistake but I've been wading through the documentation and forums and haven't found anything that works.

Hopefully someone can let me know what I'm missing.

Cheers
Tama

Avatar
Tama

13 July 2010 at 2:10pm Community Member, 130 Posts

Update: I changed "ArchivePageID" to "ArchiveParent" to prevent any conflicts and it's still not working.

Avatar
Tama

14 July 2010 at 9:07am Community Member, 130 Posts

OK, sorted it out - thanks Mateusz.

You have to remove ID from $has_one:

static $has_one = array(
'ArchivePage' => 'SiteTree',
);

But still include it in the getCMSFields:

function getCMSFields(){
$tree = new TreeDropdownField('ArchivePageID', 'Choose a Parent page to display an archive of the Child pages', 'SiteTree');
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', $tree, 'Content');

return $fields;
}