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.

Customising the CMS /

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

Attach an image to a new Page/Dataobject


Go to End


23 Posts   7376 Views

Avatar
MarcusDalgren

Community Member, 288 Posts

17 October 2012 at 4:53am

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.

Avatar
Martin D.

Community Member, 21 Posts

17 October 2012 at 5:00am

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.

Avatar
Optic Blaze

Community Member, 190 Posts

17 October 2012 at 5:02am

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/

Avatar
Martin D.

Community Member, 21 Posts

17 October 2012 at 5:06am

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

Avatar
MarcusDalgren

Community Member, 288 Posts

17 October 2012 at 5:13am

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.

Avatar
MarcusDalgren

Community Member, 288 Posts

17 October 2012 at 5:31am

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.

Avatar
Martin D.

Community Member, 21 Posts

17 October 2012 at 5:35am

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

Avatar
MarcusDalgren

Community Member, 288 Posts

17 October 2012 at 5:54am

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.