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.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

ModelAdmin $summary_fields image width


Go to End
Reply

11 Posts   4961 Views

Avatar
B-Side

4 April 2009 at 1:46pm Community Member, 42 Posts

I am setting up a data management framework using ModelAdmin in 2.3.1.

I would like to display a small image in the summary fields for data objects so users have a quick reference to a piece of artwork to select. Is there a way to use SetWidth() in the $summary_fields for the CMS?

Thanks all, Y

Avatar
Hamish

5 April 2009 at 9:04pm Community Member, 712 Posts

$summary_fields can refer to a method of your dataobject, for example 'ImageForSummaryField' where this method returns the resized image.

Avatar
B-Side

5 April 2009 at 11:04pm Community Member, 42 Posts

Thanks very much for this. Would you mind providing example code to illustrate?

Avatar
henning.blunck

13 April 2009 at 6:44pm Community Member, 6 Posts

Hey,
seems like this post contains the answer:
http://www.silverstripe.org/general-questions/show/257794
I'm pretty new to Silverstripe as well and have not yet given this solution a try, but as far I understand, you should add a static column "Thumbnail" (next question: which type?) and then add a public function getThumbnail() which than returns the image.
Please post whether this worked.

Greets,

Henning

Avatar
dacar

26 August 2009 at 1:48am Community Member, 168 Posts

Hi, i can't get it working. How can i refer to the method?

static $summary_fields = array(
      ????
   );

Avatar
Hamish

26 August 2009 at 9:52am Community Member, 712 Posts

eg (untested):

static $db = array(
   'Name' => 'Varchar',
);

static $has_one = array(
   'Image' => 'Image'
);

static $summary_fields = array(
   'Name',
   'SmallImageThumbnail'
);

function SmallImageThumbail() {
   return $this->Image()->SetHeight(40);
}

Avatar
Mad_Clog

28 September 2009 at 11:12pm Community Member, 78 Posts

I tried above example, however i get the following error message.

[User Error] Uncaught Exception: Unable to traverse to related object field [SmallImageThumbnail] on [Ticker]


No matter what I try, i can't seem to get it to work.
I tried naming the function getSmallImageThumbnail, same error.
I tried using TickerImage.CMSThumbnail, same error only with TickerImage.CMSThumbnail instead of SmallImageThumbnail.

<?php
class Ticker extends DataObject {
   static $db = array(
      'LinkType' => 'Enum(\'Internal,File,External\',\'Internal\')',
      'LinkTarget' => 'Enum(\'_self,_blank\', \'_blank\')',
      'ExternalURL' => 'Varchar(255)'
   );

   static $has_one = array(
      'TickerImage' => 'Image',
      'TickerFile' => 'File',
      'LinkTo' => 'SiteTree'
   );

   static $summary_fields = array(
      'SmallImageThumbnail',
      'LinkType'
   );

   public function SmallImageThumbnail() {
      return $this->TickerImage()->setHeight(50);
   }
}
?>

Avatar
Pigeon

29 September 2009 at 2:40am Community Member, 243 Posts

I wanted to do something very similar a few months ago and found this 'tutorial' very useful:

http://www.ssbits.com/adding-a-thumbnail-to-a-dataobjectmanager-or-complex-table-field/

Go to Top