Javascript based uploads do not properly support hook_form_alter

mkruisselbrink - March 27, 2008 - 03:37
Project:Drupal
Version:7.x-dev
Component:upload.module
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs work
Description

the upload_js function stores the updated form back into the cache before invoking hook_form_alter, because of this modifications made to the form in hook_form_alter won't work correctly when submitting the form as the form that is stored in the cache is different from the one displayed to the user. The attached patch seems to fix this.

AttachmentSizeStatusTest resultOperations
uploadjs.diff773 bytesIdleFailed: Failed to install HEAD.View details | Re-test

#1

mkruisselbrink - March 27, 2008 - 03:48

btw, the same issue seems to apply to 7.x as well, although I haven't actually tested that.

#2

mkruisselbrink - March 31, 2008 - 10:44
Version:6.1» 7.x-dev

change version to 7.x as the bug exists in both 6.x and 7.x

#3

mkruisselbrink - April 7, 2008 - 21:29

updated patch with no more trailing whitespace

AttachmentSizeStatusTest resultOperations
upload-js-fix.diff1.02 KBIdleFailed: Failed to apply patch.View details | Re-test

#4

mkruisselbrink - April 21, 2008 - 11:21

update patch to cleanly apply after string-concatenation-operator spacing changes.

AttachmentSizeStatusTest resultOperations
upload-js-fix.diff1.02 KBIdleFailed: Failed to apply patch.View details | Re-test

#5

maartenvg - September 2, 2008 - 14:42

Patch still applies correctly, but with some offset. No Simpletest fails are introduced after applying the patch.

Can you describe step by step how to reproduce the bug, because I haven't been able to check whether it actually fixes the bug? Thnx.

#6

drewish - September 19, 2008 - 18:23

mkruisselbrink, do you have a simple example module that we could use to test this out?

#7

mkruisselbrink - October 19, 2008 - 20:28

Attached a simple example module to test this, and a updated patch against a newer cvs revision. To reporoduce the problem, install this module, and than (without saving in between) upload a new attachment for a node, and enter a value in the Test field for an attachment. Without the patch applied, this will result in some warnings when you save the node; with the patch applied you'll get correct messages showing what values you entered in those fields.

AttachmentSizeStatusTest resultOperations
upload-js-fix.diff967 bytesIdleUnable to apply patch upload-js-fix_1.diffView details | Re-test
uploadbugtest.tar_.gz1.12 KBIgnoredNoneNone

#8

drewish - November 3, 2008 - 03:51

sorry for waiting so long on this but i just got around for it and couldn't test this because i'm getting fatal errors when saving nodes with uploads attached (Fatal error: Exception thrown without a stack frame in Unknown on line 0)... need to do some checking to see if i can figure out the cause.

#9

drewish - November 5, 2008 - 20:40

i can confirm that the fix works but i don't know enough about the code to say that it's the correct fix.

#10

System Message - November 16, 2008 - 21:50
Status:needs review» needs work

The last submitted patch failed testing.

#11

lilou - November 17, 2008 - 13:33

#12

mkruisselbrink - December 11, 2008 - 11:59
Status:needs review» reviewed & tested by the community

Marking this issues as reviewed, as after all it was reviewed and no problems were found.

#13

Damien Tournoud - December 11, 2008 - 12:02
Status:reviewed & tested by the community» needs review

Rule number 1: never, ever, mark your own patches as RTBC.

#14

Damien Tournoud - December 11, 2008 - 12:06

To be perfectly consistent, I think the call to drupal_alter('form', <the upload partial form>, array(), 'upload_js'); should be moved to _upload_form(). This way, we will insure that the form alter is consistent between javascript and non-javascript mode.

This definitely requires more discussion.

#15

mkruisselbrink - December 11, 2008 - 12:14

that might be a better fix, but it would be a change that potentially breaks/changes behavior of modules that current alter both the node-edit form and the upload_js form, as that change would mean that the already altered upload_js form would be inserted in the node-edit form. If that is okay as far as behavior changes go, I'll make a new patch that does that. I just tried to make this patch as non-intrusive as possible.

#16

Damien Tournoud - December 11, 2008 - 12:25

@mkruisselbrink: as far as I understand, this never worked (ie. the form was always form_altered *after* being cached back), so it can't possibly break anything :)

By the way, if you move the form_alter to _upload_form, please rename the form_id from 'upload_js' to 'upload_form'.

#17

Damien Tournoud - December 30, 2008 - 02:34
Status:needs review» needs work

CNW as per #14 and #16.

 
 

Drupal is a registered trademark of Dries Buytaert.