I noticed that the javascript upload handler "upload_js()" doesn't allow the altering of the generated form. That is because it doesn't call drupal_get_form() but form_build() and form_render() seperately. The attached patch fixes this behavior. As most time in drupal_get_form() is consumed by form_build() and form_render() anyway, this is not a performance issue (according to chx).

CommentFileSizeAuthor
#2 upload_js_0.patch669 byteskkaefer
upload_js.patch733 byteskkaefer
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Steven’s picture

Status: Needs review » Needs work

This patch can't be right. Using drupal_get_form() means a <form> tag is output, along with a hidden form id and another form token. We only want a part of the form.

kkaefer’s picture

Status: Needs work » Needs review
FileSize
669 bytes

You are right. I didn't notice that. Now just the hooks are called.

dopry’s picture

Category: task » bug
Priority: Normal » Critical

+1
Code looks good, and is necessary to getting equivalent interfaces for JS and non-js uploads.

marking as critical bug since it make the interaction between upload/form_alter inconsistent..

killes@www.drop.org’s picture

For what purpose do we need this?

nedjo’s picture

Priority: Critical » Normal

The point, I guess, is that the AJAX-supplied form elements here in theory should be available to be altered, just as other form elements are. The elements that the AJAX functions replace were generated as part of a node form, and so might have been altered (e.g., had additional classes supplied). These will be lost in the AJAX versions unless there is a way to alter them, too.

Worth addressing, but not IMO critical.

chx’s picture

I had a patch -- quite simple -- which allowed you to get the altered and built form array, it used a #return_array attribute and if it was set and TRUE, returned just after form_builder call from drupal_get_form. However, it was not accepted and thus was the function node_form_array born. This would come handy here because you are duplicating code.

kkaefer’s picture

Well, I actually wrote a module that needs to alter the upload form even after the user has uploaded something via JS. And that's the reason why I discovered this bug/lack of feature at all.

Steven’s picture

Status: Needs review » Fixed

Committed to HEAD. But if we are going to see more AHAH like this in Drupal, we'll need a more generic solution.

Anonymous’s picture

Status: Fixed » Closed (fixed)