Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Nested DOMs setUploadFolder

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 273 Views
  • cmc
    Avatar
    Community Member
    23 Posts

    Nested DOMs setUploadFolder Link to this post

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

    }

  • cmc
    Avatar
    Community Member
    23 Posts

    Re: Nested DOMs setUploadFolder Link to this post

    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.

    273 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.