I've extended the page class with some additional fields.
class Page extends SiteTree {
I've a few has_one relations and one of them is a image
private static $has_one = array(
'BackgroundImage' => 'BackgroundImage',
'BottomContentImage' => 'Image',
'NavLevel2Image' => 'Image'
);
For the CMS fields I have this:
public function getCMSFields() {
$fields = parent::getCMSFields();
$config = GridFieldConfig_RelationEditor::create();
$gridField = new GridField('BackgroundImage', 'BackgroundImage', $this->BackgroundImage(), $config);
$fields->addFieldToTab('Root.Images.Main',$gridField);
return $fields
Know I get an error for the BackgroundImage class.
[User Error] Uncaught LogicException: GridField doesn't have a modelClassName, so it doesn't know the columns of this grid.
For the info, the BackgroundImage dataobject looks like this:
<?php
class BackgroundImage extends DataObject {
public static $db = array(
);
public static $has_one = array(
'Image' => 'Image',
);
public static $summary_fields = array(
'CMSThumbnail' => 'Thumbnail',
'Title' => 'Title'
);
public static $casting = array(
'Title' => 'Varchar(255)',
'CMSThumbnail' => 'HTMLText'
);
public function updateCMSFields(FieldList $fields) {
$fields->push(new UploadField('Image',_t('BackgroundImage.Image_Title','Image')));
return $fields;
}
public function getTitle() {
$title = ' ';
if ((int) $this->ImageID > 0) {
$img = DataObject::get_by_id('Image',$this->ImageID);
if ($img) {
$title = $img->Filename;
}
}
return $title;
}
public function getCMSThumbnail() {
$rtnhtml = ' ';
/**
* @var Image $img
*/
try {
if ((int) $this->ImageID > 0) {
$img = DataObject::get_by_id('Image',$this->ImageID);
if ($img) {
$rtnhtml = $img->CMSThumbnail()->forTemplate();
}
}
} catch (Exception $e) {
$rtnhtml = ' ';
}
return $rtnhtml;
}
}
How can I thinks this error?