Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Single Album in Image Gallery Subclass

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: 1054 Views
  • tmkp
    Avatar
    Community Member
    40 Posts

    Single Album in Image Gallery Subclass Link to this post

    Hi everybody,
    we're close to finishing our first SilverStripe Project and there's two questions regarding the Image Gallery Module remaining that i just can't get my head around..

    1. I'm using a subclass of ImageGalleryPage set up like so

    class PhotoAlbumPage extends ImageGalleryPage {

    static $singular_name = 'Fotoalbum Kategorie';
    static $plural_name = 'Fotoalbum Kategorien';
    static $hide_ancestor = 'ImageGalleryPage';
       
       public static $db = array(
       );
       
       public static $has_one = array(
        'CategoryImage' => 'Image'
       );
       
       static $defaults = array (
          'CoverImageWidth' => '100',
          'CoverImageHeight' => '100',
          'ThumbnailSize' => '75',
          'Square' => '1',
          'NormalSize' => '500',
          'MediaPerPage' => '30',
          'MediaPerLine' => '6',
          'UploadLimit' => '20'
       );
       
       function getCMSFields() {
          $fields = parent::getCMSFields();
          $fields->addFieldToTab("Root.Content.Kategoriebild", new ImageField('CategoryImage', 'Kategoriebild'));
          return $fields;
       }

       
    }

    class PhotoAlbumPage_Controller extends ImageGalleryPage_Controller {

       public function getPhotoAlbumRootLink() {
          return $this->Parent()->Link();
       }
       
       public function getPhotoAlbumCategories() {
          return $this->Parent()->Children();
       }

    }

    I'm using this because i need a Category Image/Cover for each Album Page. However, I did not subclass Album or Item..

    Everything's working fine, the only problem is that if i have a PhotoAlbumPage with one single gallery in it, Silverstripe renders an empty, basic Page Template, instead of (what i believe is the default action for a single gallery page) rendering the gallery directly, bypassing the album list.

    Is there a way to control/override this behaviour?

    And 2. is there a way yet to paginate the Album List view? I don't think it's officially implemented yet, but are there any working code examples for this?

    Many thanks in advance, and good day to all of you,
    Andi

    p.s. I fully agree with other posters on this forum that Uncle Cheese's work with DOM is what makes Silverstripe stand out the most at this point. It's a great module, i really appreciate all the effort you are putting into it. Had to be said : )

    ---------------------
    Update:

    I renamed my album template from ImageGalleryPage_album.ss to PhotoAlbumPage_album.ss, and the single album view worked fine. I had been wondering before why working with the PhotoAlbumPage.ss Layout template was not working in some cases, so i ended up having two identical Templates for PhotoAlbumPage and ImageGalleryPage

    The problem seems to be in the module, because the ancestor class explicitly defaults to the ImageGalleryPage template if there's more than one album on the page.

    Changing line 327 ff. in image_gallery/code/ImageGalleryPage.php to

       public function index()
       {
             if($this->SingleAlbumView())
                return $this->renderWith(array($this->getModelClass().'_album','Page'));
             return $this->renderWith(array($this->getModelClass(),'ImageGalleryPage','Page'));
       }

    seems to do the trick. I wonder if that should be rolled in, or am i overlooking something here?

  • UncleCheese
    Avatar
    4085 Posts

    Re: Single Album in Image Gallery Subclass Link to this post

    Make sure you have created PhotoAlbumPage_album.ss

  • UncleCheese
    Avatar
    4085 Posts

    Re: Single Album in Image Gallery Subclass Link to this post

    Oops.. looks like you've already figured it out.

    Yeah, that isn't handled very well. I think what it should really do is something like

    return $this->album();

    but that action is not actually defined in the controller.

    What about $this->getViewer()? Isn't that the way you find a template? I'm getting rusty.

    1054 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.