3070 Posts in 869 Topics by 651 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 183 Views |
-
Gridfield Image Class display Thumbnail [solved]

10 February 2013 at 6:33am
I’m upgrading a site from SS2 to SS3 and there are a number of Images which are managed by ImageDOM which I am trying to move to Gridfield.
Usually I will have this:
class CustomImage extends DataObject {
public static $has_one = array (
'MyImage' => 'Image',
);
static $summary_fields = array(
'Thumbnail' => 'Thumbnail'
);public function getThumbnail() {
return $this->MyImage()->CMSThumbnail();
}
}Then if I create a gridfield Record Editor on a page this automatically gives me a thumbnail.
class Page extends SiteTree {
...
public static $has_many = array(
'CustomImages' => 'CustomImage',
);public function getGeneratedCMSFields() {
$fields = parent::getCMSFields();$conf=GridFieldConfig_RecordEditor::create(10);
$fields->addFieldToTab("Root.CustomImages", new GridField('CustomImages','', $this->CustomImages(), $conf));return $fields;
}...
}Is it possible to adapt this to work on the basic Image class? So far I have tried this, wihch I feel may be close, but I can’t work out how to get it to work.
class Page extends SiteTree {
...
$has_many = array(
'MyImages' => 'Image'
)...
public function getThumbnail() {
return $this->Image()->CMSThumbnail();
}public function getCMSFields() {
$fields = parent::getCMSFields();$conf=GridFieldConfig_RecordEditor::create(10);
$conf->getComponentByType('GridFieldDataColumns')
->setDisplayFields(array(
'Thumbnail' => 'Thumbnail'
'Title' => 'Title'
)) ;
$fields->addFieldToTab("Root.MyImages", new GridField('MyImages','', $this->MyImages(), $conf));
return $fields;
}Is it possible to display a thumbnail, or should I just re-organise the site structure?
-
Re: Gridfield Image Class display Thumbnail [solved]

10 February 2013 at 6:58am Last edited: 10 February 2013 6:58am
After getting away from the screen for a few minutes and coming back I solved it almost straight away:
public function getThumbnail() {
return $Image()->CMSThumbnail();
}...
->setDisplayFields(array(
'Image' => 'CMSThumbnail',
'Title' => 'Title'
))
;
| 183 Views | ||
|
Page:
1
|
Go to Top |

