Jump to:

23491 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » ModelAdmin $summary_fields image width

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

Page: 1 2
Go to End
Author Topic: 4922 Views
  • B-Side
    Avatar
    Community Member
    42 Posts

    ModelAdmin $summary_fields image width Link to this post

    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

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: ModelAdmin $summary_fields image width Link to this post

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

  • B-Side
    Avatar
    Community Member
    42 Posts

    Re: ModelAdmin $summary_fields image width Link to this post

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

  • henning.blunck
    Avatar
    Community Member
    6 Posts

    Re: ModelAdmin $summary_fields image width Link to this post

    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

  • dacar
    Avatar
    Community Member
    168 Posts

    Re: ModelAdmin $summary_fields image width Link to this post

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

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

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: ModelAdmin $summary_fields image width Link to this post

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

  • Mad_Clog
    Avatar
    Community Member
    78 Posts

    Re: ModelAdmin $summary_fields image width Link to this post

    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);
       }
    }
    ?>

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: ModelAdmin $summary_fields image width Link to this post

    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/

    4922 Views
Page: 1 2
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.