Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba

Nested DOMs setUploadFolder


Go to End


2 Posts   728 Views

Avatar
cmc

Community Member, 33 Posts

7 March 2012 at 3:40pm

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;
	}


}

Avatar
cmc

Community Member, 33 Posts

8 March 2012 at 2:57pm

After watching the nested DOM screencast for the 10th time, I saw that in getCMSFields_forPopup in the code below should be getCMSFields.

This tutorial specifies that getCMSFields, not getCMSFields_forPopup should be used -
http://www.ssbits.com/tutorials/2010/dataobjects-as-pages-part-1-keeping-it-simple/

With that change this mostly works as expected, after correcting the typo in SimpleHTMLEditorField.