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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

SimpleTreeDropdownField for a DataObject


Go to End


2 Posts   2727 Views

Avatar
uli

Community Member, 2 Posts

5 June 2010 at 2:32am

First post, so go easy on me... ;)

I'm having a strange issue with a class derived from DataObject and a SimpleTreeDropdownField. Here's the code:

class HomePage extends Page {
  static $has_many = array(
    'Spotlights' => 'Spotlight'
  );
  function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab('Root.Content.Focus', new DataObjectManager(
      $this,
      'Spotlights',
      'Spotlight',
      array('LinkID' => 'Linked Page', 'LinkImageID' => 'Link Image'),
      'getCMSFields_forPopup')
    );
    return $fields;
  }
}

class Spotlight extends DataObject {
  static $has_one = array(
    'Link' => 'SiteTree',
    'LinkImage' => 'Image'
  );
  function getCMSFields_forPopup() {
    return new FieldSet(
      new SimpleTreeDropdownField('LinkID', 'Page to link to', 'SiteTree'),
      new ImageField('LinkImage', 'Link image')
    );
  }
}

I get the DataObjectManager in the CMS back-end, but when I try to add an entry, I do not get the SimpleTreeDropdownField. If I change 'LinkID' to 'Link' in the SimpleTreeDropdownField call the control shows up but anything I select does not get saved to the DB (obviously).

What am I doing wrong?

I'm using SS 2.4.0.

Thanks,
Ulrich

Avatar
uli

Community Member, 2 Posts

5 June 2010 at 3:12am

Never mind... the solution is in this post.