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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

ModelAdmin $summary_fields image width


Go to End


11 Posts   7775 Views

Avatar
iON creative

Community Member, 42 Posts

4 April 2009 at 1:46pm

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

Community Member, 712 Posts

5 April 2009 at 9:04pm

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

Avatar
iON creative

Community Member, 42 Posts

5 April 2009 at 11:04pm

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

Avatar
henning.blunck

Community Member, 6 Posts

13 April 2009 at 6:44pm

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

Community Member, 173 Posts

26 August 2009 at 1:48am

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

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

Avatar
Hamish

Community Member, 712 Posts

26 August 2009 at 9:52am

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

Community Member, 78 Posts

28 September 2009 at 11:12pm

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
dhensby

Community Member, 253 Posts

29 September 2009 at 2:40am

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