Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Adding Files to Images within Image Gallery

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2 3
Go to End
Author Topic: 3789 Views
  • mattclegg
    Avatar
    Community Member
    56 Posts

    Re: Adding Files to Images within Image Gallery Link to this post

    Hey Adrian

    It seems you cant use FileDataObjectManager in this way, but you can use regular DataObjectManager to do the same thing, ie;

    <?php
    class CaseStudy extends Page {

       static $has_many = array ('CaseStudyImages' => 'CaseStudy_Image');

       public function getCMSFields() {
          $fields = parent::getCMSFields();
          $fields->addFieldToTab("Root.Content.Object",$manager = new DataObjectManager($this,'CaseStudyImages','CaseStudy_Image',array('Name' => 'Name','CMSThumbnail'=>'Preview'),'getCMSFields_forPopup',null,"Name Asc"));
       return $fields;
       }
    }
    class CaseStudy_Image extends DataObject
    {
    static $db = array (
    'Name' => 'Varchar'
    );

    static $has_one = array (
    'Attachment' => 'Image',
    'Thumbnail' => 'Image',
    'CaseStudy' => 'CaseStudy'
    );

    public function getCMSFields_forPopup()
    {
    return new FieldSet(
       new ImageField('Thumbnail'),
       new TextField('Name'),
       new ImageField('Attachment')
    );
    }
       function CMSThumbnail() {
          if ($image=$this->Thumbnail())return $image->CMSThumbnail();
          return null;
       }
    }

    This should work regardless of what version you have

  • adesweb
    Avatar
    Community Member
    39 Posts

    Re: Adding Files to Images within Image Gallery Link to this post

    OK cool, slightly different user journey, but essentially it will work, and it won't mean having to re-upload all of the images again!

    Thanks for your help

  • mattclegg
    Avatar
    Community Member
    56 Posts

    Re: Adding Files to Images within Image Gallery Link to this post

    WHAT? Why upload the images again?

    You can still attach any images that have already been uploaded to the SS filestore.

    Or you could even use a RAW SQL query to update your objects, if the structure has changed soo much?

  • adesweb
    Avatar
    Community Member
    39 Posts

    Re: Adding Files to Images within Image Gallery Link to this post

    No, I don't need to upload the images. Note the negative

    Thanks,
    Adrian

  • mattclegg
    Avatar
    Community Member
    56 Posts

    Re: Adding Files to Images within Image Gallery Link to this post

    Ah sorry, TLDR

    3789 Views
Page: 1 2 3
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.