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?