Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
When configuring Ubercart, after adding or changing the image for a product, I get this error:
warning: Invalid argument supplied for foreach() in /home/hofst12sky/public_html/sites/all/modules/filefield/filefield_field.inc on line 127.
Comment | File | Size | Author |
---|---|---|---|
#15 | 369310_200903121203+1100.patch | 698 bytes | sammys |
#8 | filefield_foreach_error.patch | 1.03 KB | quicksketch |
Comments
Comment #1
dopry CreditAttribution: dopry commentedcan you reproduce with a normal content type with a filefield? imagefield? Is it only on node creation or update? Is there an existing image?
Comment #2
nt2 CreditAttribution: nt2 commentedSame problem but with standard CCK setup. With an imagefield and on update with no existing image. Does it also on update of other data on a nodes with empty imagefields but only the first time.
Comment #3
nils.destoop CreditAttribution: nils.destoop commentedSame here:
Problem is in filefield_field.inc on line 127
// try to delete items from original node
$orig = node_load($node->nid);
// if there are, figure out which ones must go.
foreach($orig->$field['field_name'] as $oitem) {
If there are no images uploaded yet, $orig won't be an array.
Add this code in front of the foreach:
if(!is_array($orig->$field['field_name'])) {
return;
}
Comment #4
szy CreditAttribution: szy commented@zuuperman, thanks, it works indeed, I had the same problem.
Szy.
Comment #5
szy CreditAttribution: szy commentedComment #6
cameronp CreditAttribution: cameronp commentedYep same problem here... just changing status to patch so that they add the fix in..
Comment #7
SeanBannister CreditAttribution: SeanBannister commentedSame problem here
Comment #8
quicksketchThanks for nailing this down. I applied the attached fix, which should accomplish the same goal.
Comment #9
quicksketchComment #10
cside CreditAttribution: cside commentedHave applied the patch and the same error message has moved to line 129.
foreach($orig->$field['field_name'] as $oitem) {
Comment #11
quicksketchHmm. Does this occur when a node type does or does not have a FileField in it?
Comment #12
kenorb CreditAttribution: kenorb commentedMarked #372157: Invalid argument supplied for foreach() - filefield_field.inc on line 127 as duplicate.
Comment #13
kenorb CreditAttribution: kenorb commentedI've got the same problem:
It happen after I've uploaded picture to my content (via imagefield 6.x-3.0-alpha4).
Filefield: "6.x-3.0-alpha7"
It can be related to: #325097: warning: preg_match() expects parameter 2 to be string in common.inc on line 1075 and bootstrap.inc on line 732 errors
Comment #14
quicksketchI know it feels like I'm redirecting just about every issue to this patch, but could you try out #397578: Uncouple ImageField from FileField Custom Hooks and see if it corrects the problem? It removes a lot of the funky ImageField/FileField bugs when they're used together. Make sure you have a complete backup of your site (both files and database) before trying it out please.
Comment #15
sammys CreditAttribution: sammys commentedHi quicksketch,
In any case it would be better to have this part coded defensively. You can avoid the error message by simply adding a cast to an array. A FALSE or NULL will then be converted to an empty array. Here is a patch I just rolled for you that will remove the error message for now and you can concentrate on doing the decoupling.
Comment #16
quicksketchThis should be fixed by #370531: Properly Handle Revisions for document control. Please try out the development version or CVS HEAD to confirm it's really gone. The new segment of code is:
The
!empty($orig->$field['field_name'])
check should prevent this error in the case the field doesn't exist at all.