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

ParentID not needed... Maybe?


Go to End
Reply


11 Posts   2638 Views

Avatar
UncleCheese

Forum Moderator, 4094 Posts

18 December 2009 at 10:55am

How do you have your headings set up in your DOM instance?

Avatar
X10D3

Community Member, 10 Posts

18 December 2009 at 11:52am

I got it working! Here's what I have...

HOMEPAGE

class HomePage extends SiteTree
{
   public static $db = array();
   public static $has_one = array();   
   public static $has_many = array(
      'Rotator' => 'RotatorImg'
   );   
      
   function getCMSFields()
   {
      $fields = parent::getCMSFields();
      
      $fields->addFieldToTab("Root.Content.Rotator", new DataObjectManager(
         $this,
         'Rotator',
         'RotatorImg',
         array(
            'RotAlt' => 'Image Alt Text',
            'RotTitle' => 'Link Title',
            'ReturnRotEnabledYesNo' => 'Enabled',
            'ReturnRotWindowYesNo' => 'New Window',
            'Thumbnail' => 'Preview'
         ),
         'getCMSFields_forPopup'
      ));
      return $fields;
   }

....

   function GetRotator()
   {
      return DataObject::get('RotatorImg', "RotEnabled = 1", "SortOrder", "", "", "DataObjectSet");
   }

...
}

OBJECT

class RotatorImg extends DataObject
{
   static $db = array(
      'RotLink' => 'Text',
      'RotAlt' => 'Text',
      'RotTitle' => 'Text',
      'RotWindow' => 'Boolean',
      'RotEnabled' => 'Boolean'
   );
   
   static $has_one = array(
      'HomePage' => 'HomePage',
      'RotImage' => 'Image'
   );
   
   function getCMSFields_forPopup()
   {
      return new FieldSet(
         new TextField('RotAlt', "Rotator Image Alt Text"),
         new TextField('RotTitle', "Rotator Link Title"),
         new TextField('RotLink', "Rotator Link"),
         new CheckboxField('RotWindow', 'Open in new window?'),
         new CheckboxField('RotEnabled', 'Display on Website?'),
         new ImageField('RotImage', "Rotator Image")
      );
   }
   
   function Thumbnail()
   {
      if ($this->RotImage())
         return $this->RotImage()->CroppedImage(100,100);
      else
         return null;
   }
   
   function ReturnRotEnabledYesNo()
   {
      if ($this->RotEnabled)
         return "Yes";
      else
         return "No";
   }
   
   function ReturnRotWindowYesNo()
   {
      if ($this->RotWindow)
         return "Yes";
      else
         return "No";
   }
}

Avatar
X10D3

Community Member, 10 Posts

18 December 2009 at 11:53am

Anything you see that I should be doing different. I have only been working with Silverstripe for about a week. So bare with me :)

Go to Top