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.

Customising the CMS /

Attach an image to a new Page/Dataobject


Go to End
Reply


23 Posts   3352 Views

Avatar
Martin D.

Community Member, 21 Posts

29 September 2012 at 6:44am

This is as much as a question as it is a request. If a Page, or a Dataobject has a UploadField, for an image for example, the user is not allowed/able to use them before the Page/DataObject is created and saved.

I am sure I am not the only one who thinks that it is not user friendly to force the user to first create a page before being able to attach an image. As a developer, I understand that the relationship can't be established before the page is in the database but it doesn't make sense for the end user.

Does anyone know if it is going to change in the near future?

A short term solution I found is to only show the UploadField(s) if the page exists in the database:

public function getCMSFields() {
$fields = new FieldList();
$imageUploadField = new UploadField('Image');
$videoUploadField = new UploadField('Video');

$imageUploadField->setConfig('allowedMaxFileNumber', 1);
$videoUploadField->setConfig('allowedMaxFileNumber', 1);

$fields->push(new TextField('Title'));
$fields->push(new HTMLEditorField('Content'));

if ($this->ID) {
$fields->push($imageUploadField);
$fields->push($videoUploadField);
}

$fields->push(new TextField('Source'));
$fields->push(new TextareaField('Embed', 'Video embed code'));

return $fields;
}

Thanks

Avatar
camfindlay

Forum Moderator, 171 Posts

30 September 2012 at 5:33pm

Hey Martin, yes I completely agree with you... as a developer logically I know I cannot create a relationship between a file and a record if the ID for the record doesn't exist... but from a user experience in the CMS this is a terrible workflow.

I would be interested in any solutions or brainstormed possible ideas to fix this... is there any way to during the write process hold on to the ID of the file or image and create the relationship during or after the initial write?

pseudo-code:

on write

if dataobject has a file uploaded

hold on to a reference of the files ID number

write the dataobject to the DB

callback the file ID into the dataobject

write this relationship to the DB.

... also how would we deal with a has_many files?
the UploadFIeld allows us to quickly attach a bunch of files during the creation process but the supporting workflow isn't quite right yet.

Would it be as simple as on add new it actually creates the row in the DB first up? Im happy to delete of edit rows that get added and not used... any way to turn that ability on in SS?

Avatar
camfindlay

Forum Moderator, 171 Posts

30 September 2012 at 5:48pm

I've added this ticket to the issue tracker... maybe it will get tackled at some point... it's a tricky one but would be a good win to get this UX really nice.

http://open.silverstripe.org/ticket/7917

Avatar
Martin D.

Community Member, 21 Posts

2 October 2012 at 3:00am

Edited: 02/10/2012 3:01am

Good input camfindlay. Your solution would be, I think, pretty easy to implement by using hidden inputs containing the image/file ID's. It would be great to hear from a Silverstripe developer.

Avatar
MarcusDalgren

Community Member, 288 Posts

12 October 2012 at 2:34am

I'm with you guys on this one. Especially since the file is uploaded properly and gets an id before the page/dataobject is saved this really shouldn't be an issue that's that hard to solve and I just blindly assumed it was (just trying SS3 for the first time today). Since something has gone wrong and the upload field shows up during record creation now it gets really confusing.

I'll be digging into the code in the weekend and hopefully we can get this solved somehow.

Avatar
Martin D.

Community Member, 21 Posts

12 October 2012 at 4:20am

Yes, that's the other issue. The files/images are uploaded but not added to the new page. Most users will end up uploading the same file twice.

Avatar
fabrizioT

Community Member, 2 Posts

12 October 2012 at 4:54am

Edited: 12/10/2012 4:58am

Hi all,

i'm new on Silverstripe and this is (sadly) my first post.

The issue portrayed here is a very bad problem in my opinion, i wonder if/when it will be fixed.
I can't even think of forcing my customers to do a 2 steps data insertion just to add some media to a newly created page.

I highly hope in your efforts, MarcusDalgren.

Avatar
Martin D.

Community Member, 21 Posts

12 October 2012 at 6:14am

It would be great if one of the developers of Silverstripe could help us locating the "save" method that's being called when the user create a new page.

Thanks

Go to Top