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

Using Custom Classes in ImageGallery


Go to End


1771 Views

Avatar
UncleCheese

Forum Moderator, 4102 Posts

27 May 2009 at 3:40pm

From time to time the idea of adding custom fields to the ImageGallery has come up. As of the latest SVN, you can subclass the ImageGalleryPage object and specify your own classnames. Here's an example I used:

MyImageGalleryPage.php

class MyImageGalleryPage extends ImageGalleryPage
{
	protected $itemClass = "MyImageGalleryItem";
	protected $albumClass = "MyImageGalleryAlbum";
}

class MyImageGalleryPage_Controller extends ImageGalleryPage_Controller
{
}

MyImageGalleryAlbum.php

class MyImageGalleryAlbum extends ImageGalleryAlbum
{
	static $db = array (
		'ExtraAlbumField' => 'Text'
	);
	
	public function getCMSFields_forPopup()
	{
		$f = parent::getCMSFields_forPopup();
		$f->push(new TextField('ExtraAlbumField'));
		return $f;
	}
}

MyImageGalleryItem

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

Then of course you can create MyImageGalleryPage.ss, and MyImageGalleryPage_album.ss for your templates. Not very well tested, but seems to be working well.

Free at last!