Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Using Custom Classes in ImageGallery

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 889 Views
  • UncleCheese
    Avatar
    4085 Posts

    Using Custom Classes in ImageGallery Link to this post

    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!

    889 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.