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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

TreeDropdownField in DataObjectManager


Reply


3 Posts   1343 Views

Avatar
copernican

Community Member, 189 Posts

23 October 2010 at 2:42am

Hello,

I'm trying to get a TreeDropdownField in a DataObjectManager but can't seem to make it work. Here is my code
HomPage.php

//SideLinksDOM
      $SideLinksManager = new DataObjectManager(
         $this,
         'SideLinks',
         'SideLink',
         array(
             'Label' => 'Label'
         ), 'getCMSFields_forPopup'
      );
      
      $SideLinksManager->setParentClass('HomePage');
      $fields->addFieldToTab('Root.Content.SideLinks', $SideLinksManager);
      
      return $fields;

SideLink.php

class SideLink extends DataObject{
   
   static $db = array(
      'Label' => 'Varchar(150)'
      
   );
   
   static $has_one = array(
      'Parent' => 'SiteTree',
      'Target' => 'SiteTree',
      'Image' => 'Image',
      'PageLink' => 'SiteTree'
      
   );
   
   public function getCMSFields(){
      
      $treeDropDownField = new TreeDropdownField("PageLinkID", "Choose a page to link to", "SiteTree");
      
      return new FieldSet(
         new TextField('Label', 'Label'),
         $treeDropDownField
      );
   }
}

The label field shows no problem but the drop down does not show up. If I change "PageLinkID" to "PageLink' it will show up but will not expand to show any fields.

What am I doing wrong? thanks!

Avatar
UncleCheese

Forum Moderator, 4094 Posts

23 October 2010 at 3:07am

You need to use SimpleTreeDropdownField.

--------------------
SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

Avatar
copernican

Community Member, 189 Posts

23 October 2010 at 3:12am

great, thanks.

And I see in the DataObjectManager docs SimpleTreeDropdownField is listed there. arg, when I get frustrated I forget to check the most obvious places.

Thanks again.