7921 Posts in 1359 Topics by 933 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, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 398 Views |
-
shwing thumbnail summary_fields of model admin

2 December 2011 at 5:47am Last edited: 3 December 2011 6:14am
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
-
Re: shwing thumbnail summary_fields of model admin

3 December 2011 at 6:21am Last edited: 3 December 2011 6:24am
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 thisstatic $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() functionThanks
-
Re: shwing thumbnail summary_fields of model admin

8 December 2011 at 9:35am Last edited: 8 December 2011 10:24am
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
| 398 Views | ||
|
Page:
1
|
Go to Top |

