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, biapar, Willr, Ingo, swaiba, simon_w

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


Reply


937 Views

Avatar
JonoM

Community Member, 103 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 http://www.ssbits.com/snippets/2009/adding-a-thumbnail-to-a-dataobjectmanager-or-complex-table-field/ and here http://www.silverstripe.org/general-questions/show/6247 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()
{
if($this->LogoID)
return $this->Logo()->CMSThumbnail();
else
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(
         $this,
         'MyObjects',
         'MyObject',
         array(
            'Thumb' => 'Logo','Title' => 'Title' //Override $summary_fields
         ),
         'getCMSFields_forPopup'
      );
      $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(
         $this,
         'MyObjects',
         'MyObject'
      );
      $fields->addFieldToTab("Root.Content.Exhibitors", $manager);