Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » shwing thumbnail summary_fields of model admin

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: 611 Views
  • Possibles
    Avatar
    Community Member
    16 Posts

    shwing thumbnail summary_fields of model admin Link to this post

    Hello

    I'm trying to get some thumbnails to show in the summary_fields of model admin.
    I can get the ID of the photo but not the proper image.

    I have seen example with as one Relationship. but not with has many :

    Here is where I'm at :

    Work.php

    class Work extends DataObject
    {
       static $db = array(
          'Title' => 'Varchar(255)',
    'Year' => 'Int',
          'MaterialsFr' => 'Text',
          'MaterialsEn' => 'Text',
          'Editions' => 'Text',
          'Description' => 'HTMLText',
          'URLSegment' => 'Varchar(255)',
          'MetaTitle' => 'Varchar(255)'
       );

       //Set our defaults
       static $defaults = array(   
          'Title' => 'New Work',
          'URLSegment' => 'new-Work'
       );
       
       static $has_many = array(
          'Photos' => 'Photo'
       );
       
       //Relate to the Artist pages
       static $belongs_many_many = array(
          'Artists' => 'ArtistPage'
       );
       
       //Fields to show in ModelAdmin table
       static $summary_fields = array(
          'Title' => 'Title',
          'Artists' => 'Artist',
          'Photos'=> 'Photo'
       );   

       //Add an SQL index for the URLSegment
       static $indexes = array(
          "URLSegment" => true
       );   

       //Fields to search in ModelAdmin
       static $searchable_fields = array (
          'Title',
          'URLSegment',
          'Description',
          'Artists.ID' => array(
             'title' => 'Artist'
          )
       );

       public function getCMSFields()
       {
          $f = parent::getCMSFields();
          $manager = new FileDataObjectManager(
             $this, // Controller
             'Photos', // Source name
             'Photo', // Source class
             'Attachment', // File name on DataObject
             array(
          'Title' => 'Title',
    'Year' => 'Year',
          'MaterialsFr' => 'Materials Français',
          'MaterialsEn' => 'Materials English',
          'Editions' => 'Editions',
          'Description' => 'Description',
          'URLSegment' => 'URL Segment',
          'MetaTitle' => 'Meta Title'
             ), // Headings
             'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
             // Filter clause
             // Sort clause
             // Join clause
          );
          $f->addFieldToTab("Root.Photos", $manager);
          //Artists
          $Artists = DataObject::get('ArtistPage');
          $f->addFieldToTab("Root.Artists", new CheckboxsetField('Artists', 'Artists', $Artists));
    return $f;
    ...

    Photo.php

    <?php

    class Photo extends DataObject {

    static $db = array(
          'Description' => 'Text'
    );

    static $has_one = array(
    'Attachment' => 'Image',
    'Product' => 'Product',
    'Work' => 'Work'
    );
    public function getCMSFields_forPopup()
       {
          return new FieldSet(
             new TextareaField('Description'),
             new FileIFrameField('Attachment')
          );
       }
    }

    ?>

    Thanks

  • Possibles
    Avatar
    Community Member
    16 Posts

    Re: shwing thumbnail summary_fields of model admin Link to this post

    Hello

    I'm trying to build a :

    function getThumbnail()
    {
    $image= this where I don't know what to put to get my image
    return $image->CroppedImage(50,50);
    }


    and add this

       static $summary_fields = array(
       'Thumbnail' => 'The Image'
       );


    Could anyone enlight me please, I cant get the ID of photo but not the photo itself in my getThumbnai() function

    Thanks

  • Chris_Bryer
    Avatar
    Community Member
    35 Posts

    Re: shwing thumbnail summary_fields of model admin Link to this post

    you're close..
    in photo.php you defined:

    static $has_one = array(
    'Attachment' => 'Image',
    'Product' => 'Product',
    'Work' => 'Work'
    );

    so your function should be

    function getThumbnail()
    {
    if($this->Attachment()->exists()) return $this->Attachment()->CroppedImage(50,50)->forTemplate();
    }

    -Chris

    611 Views
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.