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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

ImageDataObjectManager in a DataObjectDecorator

Go to End

2 Posts   1500 Views


Community Member, 7 Posts

1 May 2010 at 6:36am

I've added an "image gallery" of sorts to a DataObject on my site and I'm trying to use ImageDataObjectManager to manage the images for each DataObject... my code looks like:

class MyObjectExtraFields extends DataObjectDecorator {
   public function extraStatics() {
      return array(
         'has_many' => array('GalleryImages' => 'MyObjectGalleryImage')

   public function updateCMSFields(FieldSet &$fields) {
      $fields->addFieldToTab('Root.GalleryImages', new ImageDataObjectManager($this->owner, 'GalleryImages', 'MyObjectGalleryImage', 'Image', array(), 'getCMSFields_forPopup'));

class MyObjectGalleryImage extends DataObject {
   static $db = array('Caption'=>'Varchar(255)', 'Description' => 'HTMLText');
   static $has_one = array('ParentMyObject' => 'MyObject', 'Image' => 'Image');
   public function getCMSFields_forPopup() { ... }

The problem I'm running into is that whenever I create a new MyObject in the admin the "Gallery Images" tab shows all of the MyObjectGalleryImages that I've added to other MyObjects, and if I delete them it removes them from every MyObject. Am I not linking something together correctly?


Forum Moderator, 4102 Posts

1 May 2010 at 6:45am

Edited: 01/05/2010 6:46am

You're going to need to use setParentClass("ClassYoureDecorating") on your DOM because it won't be able to automatically assign the parent class from within a decorator.