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

ImageDataObjectManager in a DataObjectDecorator


Reply

2 Posts   1104 Views

Avatar
briley

1 May 2010 at 6:36am Community Member, 7 Posts

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?

Avatar
UncleCheese

1 May 2010 at 6:45am (Last edited: 1 May 2010 6:46am), 4085 Posts

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.