Hi!
I am struggling to get a DataObject working with multiple image-upload.
Its working with a has_one relation as the code shows.
I can't find out the correct relations when trying to set this up with a has_many images relation. ( in MyImage )
Thanks! timo.
ProjectPage:
class ProjectPage extends Page {
static $has_many = array(
'ProjectItems' => 'ProjectItem'
);
static $description = "ProjektSeite";
static $singular_name = 'Projekt';
public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->removeFieldFromTab("Root.Main","Content");
$GridFieldConfig = GridFieldConfig_RecordEditor::create();
$GridFieldConfig->removeComponentsByType('GridFieldPaginator');
$GridFieldConfig->addComponent(new GridFieldPaginator(20));
$GridFieldConfig->addComponent(new GridFieldSortableRows('SortOrder'));
$Gridfield = new GridField("ProjectItems", "Projekte", $this->ProjectItems()->sort("SortOrder"), $GridFieldConfig);
$fields->addFieldToTab('Root.'.$this->Title, $Gridfield);
return $fields;
}
ProjectItem:
class ProjectItem extends DataObject
{
static $db = array (
'SortOrder' => 'Int',
'Title' => 'Varchar(255)',
'ShortDescription' => 'Text',
'Description' => 'Text',
'ExternalLink' => 'Varchar(255)',
'ServiceText' => 'Text'
);
static $has_one = array (
'ProjectPage' => 'ProjectPage',
'Thumbnail' => 'Image'//,
//'Images' => 'MyImage'
);
static $has_many = array (
'Images' => 'MyImage'
);
/*public static $many_many = array(
'Images' => 'MyImage'
);*/
static $summary_fields = array(
'Thumb' => 'Thumbnail',
'Title' => 'Title'
);
static $singular_name = 'Projekt';
static $plural_name = 'Projekte';
public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->removeFieldFromTab("Root.Main","SortOrder");
$fields->addFieldToTab("Root.Main", new TextField('Title', 'ProjektName'));
$fields->addFieldToTab("Root.Main", new TextareaField('ShortDescription', 'KurzText'));
$fields->addFieldToTab("Root.Main", new TextareaField('Description', 'Text'));
$fields->addFieldToTab("Root.Main", new TextField('ExternalLink', 'Link'));
$fields->addFieldToTab("Root.Main", new TextareaField('ServiceText', 'Leistungen'));
$fields->addFieldToTab("Root.Main", new UploadField('Thumbnail', 'Thumbnail'));
$myImageGridFieldConfig = GridFieldConfig_RecordEditor::create();
$myImageGridFieldConfig->addComponent(new GridFieldBulkManager());
$myImageGridFieldConfig->removeComponentsByType('GridFieldPaginator');
$myImageGridFieldConfig->addComponent(new GridFieldPaginator(20));
$myImageGridFieldConfig->addComponent(new GridFieldSortableRows('SortOrder'));
$fields->addFieldToTab("Root.Images", new GridField("Images", "Bilder", $this->Images()->sort("SortOrder"), $myImageGridFieldConfig));
return $fields;
}
MyImage:
class MyImage extends DataObject {
static $db = array (
'SortOrder' => 'Int'
);
static $has_one = array (
'Image' => 'Image',
'ProjectItem' => 'ProjectItem'
);
/*static $has_many = array (
'Images' => 'Image'
);*/
/*public static $belongs_many_many = array(
'ProjectItem' => 'ProjectItem'
);*/
static $singular_name = 'Bild';
static $plural_name = 'Bilder';
public function getCMSFields(){
$fields = parent::getCMSFields();
$fields = new FieldList(
new UploadField('Image','Photo')
);
return $fields;
}