Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Using ImageDOM in subfolders when using DataObject as Pages

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: 499 Views
  • KINKCreative
    Avatar
    Community Member
    56 Posts

    Using ImageDOM in subfolders when using DataObject as Pages Link to this post

    Hi guys, I am creating a ModelAdmin in which I will manage DataObjects, e.g. 'Project'. Each Project has a $has_many of Images that will be managed by an ImageDataObjectManager.

    I would like, upon creating a Project, to have the set of images in its unique subfolder, as there could be hundreds of Projects in my ModelAdmin.

    Now, when I create a new Project in ModelAdmin, none of the fields are set, so the IDOM's setUploadFolder method doesn't know $this->Folder, because it doesn't exist yet. How do I approach this? A few thoughts:

    a) IDOM is present and visible before I save the Project. That means I can technically upload images before I've saved. I could make IDOM invisible until I've saved and then normally upload the images. By then, the Folder will be known to IDOM.

    b) I could just run some kind of a function upon saving the Project object that will move all the Photos, if any, into the appropriate subfolder.

    I'm not that good in SS to know what needs to be done in either of the two cases. Any help on this would be appreciated.

    class Project extends DataObject {
       
       static $db = array(
    ...
          'Folder' => 'Varchar',
          ...
       );
       
       static $has_many = array (
          'Photos' => 'Photo'
       );
       
       function getCMSFields() {

          $fields=parent::getCMSFields();
          ...      
          $photoManager = new ImageDataObjectManager(
             $this, // Controller
             'Photos', // Source name
             'Image', // Source class
             'File', // File name on DataObject
             array(
                'Description'=>'Description'
             )
          );
          $photoManager->setUploadFolder($this->Folder);
          $fields->addFieldToTab("Root.Images",$photoManager);                  
          return $fields;
       }
    }

  • KINKCreative
    Avatar
    Community Member
    56 Posts

    Re: Using ImageDOM in subfolders when using DataObject as Pages Link to this post

    Ha, alright... I found this and it's probably the best solution).

    I just used:

    if($this->ID) {
    //any fields that need the record to be saved first e.g upload fields, ImageDOM etc.
    }

    Thanks!

    499 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.