Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Thumbnails for HasManydataobjectmanager & ManyManydataobjectmanager - can't use $summary_fields?

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 840 Views
  • JonoM
    Community Member
    103 Posts

    Thumbnails for HasManydataobjectmanager & ManyManydataobjectmanager - can't use $summary_fields? Link to this post

    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()
    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);

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.