It appears the nodeapi 'view' hook receives the 'files' as arrays instead of objects during node preview. So theme_upload_attachments gets FALSE for $file->list (even when $file['list'] is true) and doesn't display. After casting to object, the $href definition checks $file->fid.. for a newly uploaded file this is something like 'upload_0' so I changed this to a strpos check. Finally, l($text, $href) is called when $href is already an url (not a path) and $text is already check_plain'ed. Patch attached, hope this helps.

Comments

mindless’s picture

maybe also change if ($file->list) to if ($file->list && empty($file->remove)) so the preview doesn't show attachments you selected for removal.

mindless’s picture

Bump.. I hope someone can review this patch, thanks.

gerhard killesreiter’s picture

Version: 4.7.2 » x.y.z

moving this to CVS. It should be reviewed there, applied and backported, if neccessary.

beginner’s picture

bookmarking. I'll try to review later this week.

beginner’s picture

Status: Needs review » Needs work

Ok, the patch looks good overall, but I have a problem with the url created for an uploaded file.
I am getting urls like: http://127.0.0.1/drupal/70742-cvs/?q=/drupal/70742-cvs/?q=files/robots.txt.
so the url formatting needs work.

Also, can you explain what exactly happens to the files? They are not already uploaded, are they? They are still in the /tmp directory. So what would happen if during the preview I click on the url for the file that I am uploading?
Wouldn't it be more accurate NOT to print a link, but to print the file name with the mention that it is uploading?

Comment #1 is valid, and fix may be included in this patch.

mindless’s picture

I only changed the conditional to decide which form to use.. I don't know why you see a URL like that.. is fixing this part of the code I didn't touch required to get this fix put into CVS?
The uploaded file is in a tmp location as you suggest.. I believe the links do work (see "Add handlers for previewing new uploads" comment in upload_menu), except in this case: http://drupal.org/node/68685
Let me know how I can help get this fix accepted, thanks.

beginner’s picture

Version: x.y.z » 6.x-dev

Does the patch in the following issue fix the current issue?
http://drupal.org/node/104047 node previews broken by missing hook_submit

mindless’s picture

I rolled back my patch and applied that one.. new file attachments NOT shown in node preview. Added back my patch, worked again.

beginner’s picture

Good to know. Thanks.

mindless’s picture

Status: Needs work » Needs review
StatusFileSize
new979 bytes

Revisited this and fixed the problem mentioned in comment #5 (found other code in upload.module that does correctly what theme_upload_attachments had wrong in creating the url). Updated patch against current HEAD rev of upload.module is attached. Please review, thanks!

ChrisKennedy’s picture

Status: Needs review » Needs work

Patch works for me.

However, there should be a comment to explain the use of the strpos() check, and the patch should be re-rolled from the Drupal root directory.

mindless’s picture

Status: Needs work » Needs review
StatusFileSize
new1.84 KB

New patch attached, thanks for testing.

dries’s picture

Version: 6.x-dev » 5.x-dev

Committed to CVS HEAD.

Neil: this probably needs to be verified and committed against DRUPAL-5.

drumm’s picture

Version: 5.x-dev » 4.7.x-dev

Committed to 5.

This might need to go in 4.7

killes@www.drop.org’s picture

Status: Needs review » Fixed

backported.

Anonymous’s picture

Status: Fixed » Closed (fixed)