Jump to:

5554 Posts in 1742 Topics by 1227 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Image Field Not Showing Attached Image

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

Page: 1
Go to End
Author Topic: 1553 Views
  • zenmonkey
    Community Member
    528 Posts

    Image Field Not Showing Attached Image Link to this post

    I'm having a problem. I have multiple Images Attached to a DataObject and an onBeforeWrite that builds relation to the image file based on Data on DataObject. This all works fine. however the when I open the DataObject in ModelAdmin the attached images don't show up in the ImageField. The images IDs associate properly as I'm using a custom getter for the Summary FIelds and I can see the images with it.

    Has One Relation:

       static $has_one = array (
          "FrontWeb_Image" => "BetterImage",
          "BackWeb_Image" => "BetterImage",
          "FrontHi_Image" => "BetterImage",
          "BackHi_Image" => "BetterImage",

    Custom Getter for Summary Field:

       public function getSummaryImage() {
          if ($this->FrontWeb_ImageID) {
             $image = DataObject::get_by_id("File", $this->FrontWeb_ImageID);
             return $image->setWidth(100);
          } else {
             return "No Image Available";   

    BetterImage is just an image quality function based on http://www.ssbits.com/tutorials/2011/improving-image-quality-by-preventing-correctly-sized-images-being-resized/

    The Thumbnails do show if I manually add the image from the ImageField.

    If this is impossible another option I'm willing to use is listing the images in a CompositeField but custom getters won't work inside the getCMSFields function.

    Thanks for any help

  • monk
    Community Member
    5 Posts

    Re: Image Field Not Showing Attached Image Link to this post

    $image = DataObject::get_by_id("File", $this->FrontWeb_ImageID);
    return $image->setWidth(100);

    instead $image->setWidth(100); use getFormattedImage() like so:

    return $image->getFormattedImage('SetWidth', 100);

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.