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