Hello all,

Thank you for your efforts in teaching us best practices! I would like to view an example about how to create a node with a multiple image field (probably including ajax...). I have seen such a node example on D7 where we'll have api field but for D6 it is more difficult and ... I need a best practice solution...

Anyway thank you all for your efforts. I really love this project.

Best regards,
Marcel

Comments

rfay’s picture

In Drupal 6 imagefield is a CCK feature, and we try to do just core stuff. However, CCK is close to core :-)

Whenever possible, of course, one should use CCK/fields to do custom nodes. See also #794492: CCK custom field example

rfay’s picture

Title: I would like to view an example for an image upload » Image upload/file upload
Component: Node Example » File Example

I do think the Form Example needs a file upload, as that's a pretty obscure piece of art.

eojthebrave’s picture

The image_example module uses #managed_file and demonstrates it's use to upload files. Should be pretty easy to rip that off and include it in the form_example module.

googletorp’s picture

Status: Active » Needs review
StatusFileSize
new8.12 KB

I created a patch for this. I didn't look at the image_example module, as I had just done something similar, only for a theme settings form instead of a node form.

There is an issue doing this in Drupal 6 with the node form because of #241364: $form_state not passed to hook_validate()/hook_node_validate(), and not passed by reference to hook_form(). The problem is basically that there's not a method with the FAPI to send the fid of the saved file along to the insert and update hooks. I solved this saving the fid in the user's session instead, and removing it again once the node has been saved/updated.

Anyways, take a look at it and let me know.

googletorp’s picture

StatusFileSize
new7.23 KB

Updated patch to current and tweaked it a bit.

Do you have some ideas to how to test file uplaod? I haven't used the Drupal testing framework that much.

Status: Needs review » Needs work

The last submitted patch, examples.node_example_file_upload_2.patch, failed testing.

googletorp’s picture

Status: Needs work » Needs review
StatusFileSize
new7.28 KB

Updated the flaw in the patch.

Status: Needs review » Needs work

The last submitted patch, examples.node_example_file_upload_3.patch, failed testing.

googletorp’s picture

StatusFileSize
new7.26 KB

Ups, try same patch formatted as CVS instead of git.

rfay’s picture

Status: Needs work » Needs review
rfay’s picture

Component: File Example » Form Example
Status: Needs review » Needs work

@googletorp, I really apologize. In #2 I mistakenly put this as file_example, when I said in the text it should be added to form_example. I'm pretty sure form_example is where it belongs :-(

It can go in a separate inc file, which should use successfully what you've already done.

rfay’s picture

Just noticed Upload Element project for D6, which may provide inspiration.

googletorp’s picture

Status: Needs work » Needs review
StatusFileSize
new3.45 KB

I've been a bit more busy than I thought I would have been, but I finally was able to use the time needed to make this patch.

I recreated the patch for the form example. It was easier than trying to convert it anyways. I had some ready more code from a previous project that I could more or less c/p and add a few comments and tweaks.

Anyways for this patch I haven't added any tests. I'm not sure how to best do tests on fileuploads, if you have any pointers, I'll try to add some tests as well for the file upload.

rfay’s picture

Hi Googletorp!

For test ideas, take a look at the core test suites for file.module in D7. I think that might offer some good clues. Congratulations on getting this going.

googletorp’s picture

Tests included. Let me know what you think.

rfay’s picture

I'm teaching this week so won't get to review soon. @ilo - want to see what you think?

ilo’s picture

sure, later I'll do.

ilo’s picture

Status: Needs review » Fixed
StatusFileSize
new10.47 KB

Thank you so much both, googletrop and rfay, The example looks good, and I've done manual and automatic testing and works fine. The patch was wrong because it was not generated from the last -dev version, googletrop, where the element example turns the patch impossible to apply. Some tweakings has been done, the menu entry for the 11th is now in the right place.

Anyway, I've rerolled, forget about the cosmetic changes. It is committed to DRUPAL-6--1: http://drupal.org/cvs?commit=432268

Thanks again!

I've included the patch.

ilo’s picture

Title: Image upload/file upload » Image upload/file upload in form example
Version: 6.x-1.x-dev »
Status: Fixed » Patch (to be ported)

Lets get this back again to live :)

googletorp’s picture

I ported the patch, after all I did check out D7 on how the tests was done.

googletorp’s picture

Status: Patch (to be ported) » Needs review

Opps, forgot to set status.

ilo’s picture

Status: Needs review » Needs work

googletorp, thank you so much!!

unfortunatelly, before working on this, I guess it is better to have this other one: #870906: Explain #tree in element example (and rework Element Example!) commited, because rerolling would be hard due to its size.. That one is waiting for a serious review. In fact, there is a bug currently preventing the form testcase to case that is solved in the issue I mentioned.

keep the good work, as rfay sais!

rfay’s picture

Status: Needs work » Needs review

#20 passes now.

ilo’s picture

Status: Needs review » Reviewed & tested by the community

I changed my mind, and as long as the element example requires a major review (and probably rewrite) I think we can go on with this one first and then reroll the element example later.

rfay’s picture

I'm ready to commit this, but having trouble with the testbots.

rfay’s picture

rfay’s picture

rfay’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.