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

Using Custom Classes in ImageGallery


Reply


1036 Views

Avatar
UncleCheese

Forum Moderator, 4094 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!