A few questions re: nested DataObjectManager.
1) I'm trying to setUploadFolder for nested DOMs. The code below is not working. Files are uploaded to "Uploads".
2) Though the Images are near their respective Alt Text fields in the CourseAdvertisement->getCMSFields_forPopup() FieldSet, they don't appear nearby in the popup window. Also the setUploadFolder in CourseSalesPage->getCMSFields() doesn't seem to have any effect. Images are also uploaded to 'Uploads'.
3) How do I specify field types? The specification in the CourseAdvertisement->getCMSFields_forPopup() FieldSet don't seem to have any effect. If I try to add them in an array in the CourseSalesPage DataObjectManager instantiation, or call getCMSFields_forPopup there, the admin throws errors.
class CourseAdvertisement extends DataObject {
public static $db = array (
'CourseName' => 'Text',
'CourseDescription'=> 'HTMLText',
'CourseBuyNowButtonCode' => 'HTMLText',
'CourseMainImageAltText' => 'Text',
'CourseSmallImageAltText' => 'Text',
'CourseAdditionalDescription' => 'HTMLText'
);
static $has_one = array (
'CourseMainImage' => 'Image',
'CourseSmallImage' => 'Image',
'CourseSalesPage' => 'CourseSalesPage'
);
static $has_many = array (
'Files' =>'CourseAdvertisementFile'
);
public function getCMSFields_forPopup() {
$files = new FileDataObjectManager (
$this,
'Files',
'CourseAdvertisementFile',
'File',
array(
'FileName' => 'Name',
'FileDescription' => 'Description'
)
);
$files->allowUploadFolderSelection = false;
$files->setUploadFolder('Uploads/CourseSalesFiles');
$files->setAddTitle('File');
return new FieldSet(
new TextField('CourseName', 'Course Name'),
new SimpleHTMLEditorFieldField('CourseDescription', 'Course Description'),
new TextField('CourseBuyNowButtonCode', 'Buy Now Button Code'),
new ImageField('CourseMainImage', 'Main Image'),
new TextField('CourseMainImageAltText', 'Alternate Text for Main Image'),
new ImageField('CourseSmallImage', 'Small Image'),
new TextField('CourseSmallImageAltText', 'Alternate Text for Small Image'),
new TextField('CourseAdditionalDescription', 'Additional Description (below small image on right)'),
$files
);
}
}
class CourseSalesPage extends Page {
public static $allowed_actions = array (
);
public static $db = array(
);
public static $has_one = array(
);
public static $has_many = array(
'CourseAdvertisements' => 'CourseAdvertisement'
);
function getCMSFields() {
$fields = parent::getCMSFields();
//drag and drop-ability is set in mysite/_config.php sortable
$courses = new ImageDataObjectManager (
$this,
'CourseAdvertisements',
'CourseAdvertisement'
);
$courses->allowUploadFolderSelection = false;
$courses->setUploadFolder('Uploads/CourseSalesImages');
$fields->addFieldToTab('Root.Content.Courses', $courses);
return $fields;
}
}