Jump to:

5514 Posts in 1733 Topics by 1219 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Attach an image to a new Page/Dataobject

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

Page: 1 2 3
Go to End
Author Topic: 2992 Views
  • MarcusDalgren
    Avatar
    Community Member
    288 Posts

    Re: Attach an image to a new Page/Dataobject Link to this post

    Ok I've just finished my first stab at solving this.

    I'm working from one limited scenario right now, image attached to data object that's related to a page and just one image/data object.
    As long as we're dealing with one image it's a has_one and the field is actually present on the data object which makes it simpler.
    However even this has proven to be rather tricky. I think I can get the functionality running on pages rather quickly but I think multi upload is going to be hard. I'm not sure if defining a many_many relationship works before the object is actually created and has an ID.

  • Martin D.
    Avatar
    Community Member
    21 Posts

    Re: Attach an image to a new Page/Dataobject Link to this post

    Sounds good MarcusDalgren. Feel free to post your code, either here or on github (fork the project). I will get into the code once I get some free time.

  • Optic Blaze
    Avatar
    Community Member
    161 Posts

    Re: Attach an image to a new Page/Dataobject Link to this post

    Hi, someone wrote a gallery module that deals with these issues:
    - multiple upload to gallery
    - drag and drop ordering
    - adding new image with 1 click
    - updating multiple files titles at once

    I have tried this image gallery and it works well. check it out

    http://www.silverstriperesources.com/modules/silvestripe-3-gallery-plugin-module/

  • Martin D.
    Avatar
    Community Member
    21 Posts

    Re: Attach an image to a new Page/Dataobject Link to this post

    Optic Blaze, so does the module let you upload images even before saving/creating the main page?

  • MarcusDalgren
    Avatar
    Community Member
    288 Posts

    Re: Attach an image to a new Page/Dataobject Link to this post

    The code I've written so far is available here: https://github.com/raket/sapphire/tree/upload-field-save-on-new
    This is still in its early stages so run this on your own risk.

    I will have a look at the Image gallery module to see if it actually solves this.

  • MarcusDalgren
    Avatar
    Community Member
    288 Posts

    Re: Attach an image to a new Page/Dataobject Link to this post

    Ok I've had a look at the module that handles this (bulk upload) and it does indeed provide a solution.
    However the way in which its done does have its risks. If you're using it for bulk creation of DO:s with one image attached (my scenario) it actually creates as many new DO:s as images uploaded. As long as you press Cancel & Delete all you're all good but if you would happen to navigate away from the page in some other way you'll have empty DO:s all over the place.

    Not the authors fault per se but it really isn't a good solution. You shouldn't have to pre create objects just in case they get saved.

  • Martin D.
    Avatar
    Community Member
    21 Posts

    Re: Attach an image to a new Page/Dataobject Link to this post

    Agreed.
    I had a temporary solution that used the same mechanism but the database ended up having lots of empty records.

  • MarcusDalgren
    Avatar
    Community Member
    288 Posts

    Re: Attach an image to a new Page/Dataobject Link to this post

    Just had a look at pages and they aren't an issue since pages are created as drafts when you click "Create new". This limits us to DO:s only which is really nice. I haven't tried the multi upload yet but I will be giving that a go tomorrow.

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