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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Thumbnails for HasManydataobjectmanager & ManyManydataobjectmanager - can't use $summary_fields?

Go to End



Community Member, 130 Posts

3 April 2011 at 4:12pm

I had a situation where I wanted to produce a thumbnail image for a dataobject in a many-many relation in both a data object manager and a complex table field automatically, using $summary_fields.

I followed two different techniques outlined here and here but couldn't quite get things to work.

In then end I determined (I think) that if you try to build a HasManydataobjectmanager or ManyManydataobjectmanager using shorthand, and you have calls to methods in $summary_fields such as 'Logo.CMSThumbnail.Tag' it will break the manager and return an error. I think this is a bug but I wouldn't have a clue how to fix it - but if you're reading this Uncle Cheese maybe you can look in to it?

I got around it by combining the two techniques - referencing an image function in $summary_fields for use in complex table fields or straightforward DataObjectManagers, and defining a separate function for HasManydataobjectmanagers and ManyManydataobjectmanagers, then building those the long way rather than using shorthand and relying on $summary_fields.

For anyone who had the same problem as me here's what I did:

On the data object class:

	static $has_one = array (
		'Logo' => 'Image'

	static $summary_fields = array(
        'Logo.CMSThumbnail.Tag' => 'Thumbnail',
        'Title' => 'Title'

    //Generate a thumbnail for the DOM
    public function getThumb()
            return $this->Logo()->CMSThumbnail();
            return '(No Image)';

Example - On a related class such as a page with ManyManyDataObjectManager - overwrite $summary_fields

	function getCMSFields() {
		$fields = parent::getCMSFields();
		//Set up DOM
		$manager = new ManyManyDataObjectManager(
				'Thumb' => 'Logo','Title' => 'Title' //Override $summary_fields
		$fields->addFieldToTab("Root.Content.Exhibitors", $manager);

or on a normal DataObjectManager - use the $summary_fields

	function getCMSFields() {
		$fields = parent::getCMSFields();
		//Set up DOM
		$manager = new DataObjectManager(
		$fields->addFieldToTab("Root.Content.Exhibitors", $manager);