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.

Customising the CMS

Getting first image thumbnail from a has_many


Reply

2 Posts   347 Views

Avatar
Matty Balaam

13 October 2013 at 1:44am Community Member, 69 Posts

I have a gridfield in SectionPage managing a has_many dataobject 'Sections' => 'Section', which in turn has_many 'Gallery' => 'GalleryItem' which has_one image.

How can I get the Gridfield to return a thumbnail of the first GalleryItem?

I have tried many variations in Section.php, but feel this is the closest I have got:

   public function getThumbnail() {
      return $this->Gallery()->First()->Photo()->CMSThumbnail();
   }

This gives me a 'Call to a member function Photo() on a non-object in...' error.

Can anyone give me some help with this problem?

Avatar
zenmonkey

14 October 2013 at 6:41pm Community Member, 528 Posts

Make sure $this->Gallery()->First() is returning an object and not just a VIewableData array. I know I've run into this in the past

It may alos work to create a getThumbnial on GalleryItem and set it as virtual property