If a user uploads a file, then submits and validation fails, the 'Private' checkbox disappears. The result is that the file definitely goes public.

I have looked a bit into it, looks like the module's theme function isn't used anymore after validation fails. A possible reason might be that the theme function is changed during form_alter, and form_alter does not get triggered on validation failure (although I used to think that the '#theme' would be saved in the form_cache...)

Best regards,
Khaled

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

berliner’s picture

I confirm this error. Might be related to #671574: Document that hook_form_alter not called after a form fails validation

I tested further and tried to move some logic from hook_form_alter to a function called after the build, but it didn't work for me neither. Anyone any idea?

berliner’s picture

Status: Active » Needs review
FileSize
9.85 KB

After digging through the code of the private_upload module and the core upload module I think the problem is, that upload_js() overwrites the cached form and thus the changes made by private_upload's implementation of hook_form_alter().

I tried to cope with this issue in re-implementing the form cache strategy of the upload module into private_upload. See the attached patch that solves the issue for me. It includes a change to the hook_nodeapi() implementation in order to give all files that are attached to a node a private attribute, reflecting the private state of each file. Also I removed private_upload_form_validate() and private_upload_form_submit() because the former is never used and I couldn't see why it should be. The latter is not necessary anymore with the new changes, because the private checkbox now integrates correctly into the form and its value is accessible in nodeapi's insert/update operation.

I would have liked to keep this patch smaller, but the changes were rather substantial.

berliner’s picture

The last patch didn't work when previewing a node. Should be fixed now.