Hey guys,
I'm having trouble using the ImageDataObjectManager in my app. It works great if I assign an ImageDataObjectManager directly to a pages getCMSFields method, but in my particular case, a page can have assigned to it multiple Projects (using ComplexTableField) and each Project can have multiple images (thus the ImageDataObjectManager). When I put the setup for the ImageDataObjectManager in the Project classes getCMSFields_forPopup, it fails. I see a tab created for it in the popup, but the tab contains a single line table with no means to add / edit / remove items.
Here's the code:
Page
class GalleryPage extends Page
{
static $singular_name = 'Gallery page';
static $plural_name = 'Gallery pages';
static $has_many = array (
'Projects' => 'Project'
);
function getCMSFields()
{
$fields = parent::getCMSFields();
$projectsTable = new ComplexTableField($this, 'Projects', 'Project');
$fields->addFieldToTab('Root.Content.Projects', $projectsTable);
return $fields;
}
}
Project
class Project extends DataObject
{
static $db = array (
'Title' => 'Varchar(255)',
'Description' => 'Text',
'Technologies' => 'Varchar(255)'
);
static $has_many = array (
'GalleryImages' => 'GalleryImage'
);
static $has_one = array (
'BelongToGalleryPage' => 'GalleryPage'
);
function getCMSFields_forPopup()
{
$manager = new ImageDataObjectManager(
$this, // Controller
'GalleryImages', // Source name
'GalleryImage', // Source class
'GalleryImageURL', // File name on DataObject
array(
'Label' => 'Title'
),
'getCMSFields_forPopup'
);
$manager->setSingleTitle('Gallery');
$manager->setPluralTitle('Gallery');
$fields = new FieldSet(
new TextField('Title'),
new SimpleHTMLEditorField('Description'),
new TextField('Technologies'),
$manager
);
return $fields;
}
}
GalleryImage
class GalleryImage extends DataObject
{
static $db = array (
'Label' => 'Text'
);
static $has_one = array (
'GalleryImageURL' => 'Image', //relation needed for this DataObject
'BelongToProject' => 'Project' //relation needed to point back to your pagetype, my pagetype is Project.
);
public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Label'),
new FileIFrameField('GalleryImageURL')
);
}
public function IsFirst(){
return $this->iteratorPos == 0;
}
}
The code looks good to me (logically), and being able to get it running directly in the page shows I have all the necessary module stuff installed. Can anyone see what I might be doing wrong?
Thanks loads,
Lee