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

ImageDataObjectManager: Is it possible to set title on Image?


Go to End


2 Posts   2628 Views

Avatar
jjeziorski

Community Member, 11 Posts

5 July 2009 at 5:22am

Hey,
I like this module very much. Great work!
I have an ImageDataObjectManager running smoothly with simple DataObject (just image, parentPage and title). However, I wonder is it possible to work with image object "Title" rather than extra property?

I imagine two approaches:
1. use an object extending Image class

class PageImage extends Image
{
	static $has_one = array (
		'ParentPage' => 'Page'
	);
	
	public function getCMSFields_forPopup()
	{
		return new FieldSet(
			new TextField('Title'),
			new FileIFrameField('GD')
		);
	}
}

However this won't satisfy ImageDataObjectManager constructor parameters and has awkward Image field

2. use Dataobject and write "Title" to Image object

class PageImage extends DataObject
{
	static $has_one = array (
		'Photo' => 'Image',
		'ParentPage' => 'Page'
	);
	
	public function getCMSFields_forPopup()
	{
		return new FieldSet(
			new TextField('Photo.Title'),
			new FileIFrameField('Photo')
		);
	}
}

This seems coherent, however it doesn't work ;)

Am i doing something wrong? Any ideas?

Thanks,

Avatar
UncleCheese

Forum Moderator, 4102 Posts

6 July 2009 at 11:57am

Edited: 06/07/2009 11:59am

It sounds like what you want is to extend the ImageGalleryItem class.

class MyImage extends ImageGalleryItem
{
static $db = array (
'MyField' => 'Text'
);
public function getCMSFields_forPopup();
{
$f = parent::getCMSFields_forPopup();
$f->push(new TextField('Title'));
return $f;
}
}

Then you need to create a custom ImageGalleryPage class, too.

class MyImageGalleryPage extends ImageGalleryPage
{
public $itemClass = "MyImage";
}

I wouldn't use Title as a custom field, though, because it's already on the Image object associated with ImageGalleryItem.