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

How to replicate ImageDataObjectManager behaviour in SS3?

Go to End

5 Posts   2005 Views


Community Member, 130 Posts

13 September 2012 at 8:47am

Edited: 13/09/2012 8:48am

Does anyone know how to replicate ImageDataObjectManager behaviour in SS3? I'm referring to the ability to have a class such as this:

class PhotoGalleryImage extends DataObject
	static $db = array (
		'Caption' => 'Text'
	static $has_one = array (
		'Image' => 'Image',
		'PhotoGalleryPage' => 'PhotoGalleryPage'

Where the focus of the object is on the image relationship, and easily import a bunch of photos at once in to a page like this:

class PhotoGalleryPage extends Page {
	static $has_many = array (
		'PhotoGalleryImages' => 'PhotoGalleryImage'
	public function getCMSFields() {
		$fields = parent::getCMSFields();

		//What to put here??

		return $fields;

Then add captions etc. if necessary afterwards. I tried using GridField but the best I could get to happen is to create one PhotoGalleryImage object at a time - which then has to be saved before adding an image to it. Very time consuming compared to the old way of doing it with ImageDOM and Uploadify!

Thanks for reading


Community Member, 545 Posts

7 December 2012 at 1:36am

I just ended up extending the image class with the extra fields and just using the upload field. You upload all the images an hit edit on it to add the extra stuff. Not quite as good as the ImageDOM but its works better than the 1 at a time.


Community Member, 130 Posts

11 December 2012 at 8:37am

Hi zenmonkey, thanks for the reply - any chance you could provide the code you used for this? Sounds like a good solution.



Community Member, 545 Posts

12 December 2012 at 5:16am

There's two ways to handle this extension either create a new inidividual class or extend the whole image class. I chose the second way since the option could be used on multiple relations.

Here is the code

The image extension

class CustomImageExtension extends DataExtension {
	static $db = array(
 		'Feature' => 'Boolean',
 		'Caption' => 'Varchar',
 		'Cover' => 'Boolean'
 	static $has_one = array(
 		'Listing' => 'Listing',
 		'Room' => 'Room',
 		'MLSListing' => 'MLSListing'
 	public function updateCMSFields(FieldList $fields) { 
		$fields->addFieldToTab('Root.Main', new TextField('Caption', 'Caption'), 'Name');
		$fields->addFieldToTab('Root.Main', new CheckboxField('Feature', 'Is Feature'), 'Name'); 
		$fields->addFieldToTab('Root.Main', new CheckboxField('Cover', 'Is Cover'), 'Name'); 

Then in your config add
Object::add_extension('Image', 'CustomImageExtension');

This adds those fields to all Image Objects, the indidual class option instead of extending DataExtension you'd extend the Image, forget about the line in your config and on your dataobject call the relation to CustomImage instead of Image. Really depends on the functionality you need. I was really just adding a few booleans so I could pull feature image into carousels on parent pages, as I need this on almost every instance of image I just added to the Image Class

Hope that helps


Community Member, 130 Posts

12 December 2012 at 5:57am

Thanks man!