I'm not entirely sure this is a CCK problem or a usernode problem, but the error message I'm receiving cites the fieldgroup.module, so I'm posting this here first.
I've created custom profiles using usernode and CCK (not nodeprofile). I've added quite a few custom fields for the usernode content type, and have thus enabled the fieldgroup.module to keep things tidy. For the usernodes that already exist, all is fine and good. The problem comes when I create a new user account and attempt to login. Upon login (which is successful), the following error message is given when the user is taken to his/her usernode/profile page:
warning: Invalid argument supplied for foreach() in /home/website/public_html/drupal/sites/all/modules/cck/fieldgroup.module on line 394.
This may be related to the fact that the new node usernode creates for a user does not automatically populate any of the custom fields...?
As I said, I'm not sure if this is a problem with usernode or cck. It seems similar to this problem: http://drupal.org/node/156598. Any assistance would be much appreciated. Here's some relevant info about my setup:
Drupal 5.2
CCK 5.x-1.6
Usernode 5.x-1.2
Contemplate 5.x-1.3
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | fieldgroup.module_2.patch | 1.38 KB | jenlampton |
Comments
Comment #1
holydrupal commentedI have the same error and I don't use Usernode some it's a CCK bug
error is in front-page although I don't have any CCK content in my front page
Comment #2
bengtan commentedI ran into the same bug with CCK 5.x-1-6-1, though from an entirely different context, and came up with a one-line workaround.
In modules/cck/fieldgroup.module, around line 394, find the line which says:
foreach ($group['fields'] as $field_name => $field) {
and change it to:
if (!empty($group['fields'])) foreach ($group['fields'] as $field_name => $field) {
Try it and see if it fixes your problem.
Please note this one-liner is not the official solution. It's more of a proof-of-concept. Once proven, the module maintainer should incorporate it into a release.
The bug seems to manifest when $group['fields'] is an empty array. The php foreach statement should handle an empty array, but apparently not. I would say this is a PHP bug, not a drupal one.
Comment #3
RobRoy commentedIf $group['fields'] was an empty array it would be fine. It's most likely not set. Probably best to find the source of the problem and make sure that isn't a bug. If not, a check for isset($group['fields']) && is_array($group['fields']) is a better error check as 'blah' is !empty but we really want to make sure it's an array.
Comment #4
bengtan commentedI put in some debugging just before the suspect foreach like so:
and got the following dump:
$group['fields'] looks like an empty array to me. Unless I'm misreading the dump?
Comment #5
RobRoy commentedIf $group['fields'] is an empty array, then the error must be coming from somewhere else as that's valid to pass to foreach.
Comment #6
spazfoxThanks for the assistance. Unfortunately, I tried modifying fieldgroup.module as suggested, but am still experiencing the error.
Comment #7
ChineseGuy commentedThanks, solution worked for me.
Comment #8
jpsalter commentedSolution in #2 worked for me (I had nodereference fields causing this error when no nodes were referenced).
Comment #9
spazfoxI found one more instance of
foreach ($group['fields'] as $field_name => $field) {in fieldgroup.module and also modified it as suggested in #2.This made it so that I no longer receive the invalid argument error (woo-hoo!), but my usernodes still are not being created (*sigh*). This suggests that my problem may be with usernode, at least (or perhaps some way in which usernode is interacting with cck).
Comment #10
fagoI had already a look at the code, and I can't see any errors there. I ran over these problem already myself - the fix was to fix the calling code!
I suppose the warning occurs if fieldgroup *tries* to work with a $node which is NULL or more specific with $node->type == ''. So if these warnings occur, they are probably caused by other modules. Try deactivating modules until the error goes away...
So I set this to won't fix.
Comment #11
fagoComment #12
fagoor better to something else, so that the issue is visible in the queue
Comment #13
jiangxijay commentedFYI. I started seeing this problem when I installed node_approval.
Comment #14
bengtan commentedThere's actually two distinct issues here. One is the warning from the fieldgroup module. The other is spazfox's problem of usernodes not being created.
Now, I don't know anything about usernodes since I have never tried using that module. I only came across this issue because I ran into the fieldgroup warnings (from an entirely different context). When I was searching the issue, I got the impression that other situations can cause the warnings as well.
I think a fix for these warnings is still important and warranted.
The problem with usernodes . . . I don't know about.
Perhaps we can somehow split this issue into two and mark one as active (or fixed) and mark the other as postponed?
Comment #15
bengtan commentedGrrr.... let me rephrase myself.
I agree that the warnings are triggered from other code/modules calling into fieldgroup.module with null parameters or empty values or whatever and ideally should be fixed there. However, it's unlikely that all these incorrect calls will be patched up anytime soon, so perhaps it's worth preventing them from within fieldgroup.module as well?
Yes, it's just a warning, and probably benign, but it is a little bit scary to see them pop up. And then the user will spend up to a couple of hours trying to diagnose a bug which isn't really significant.
Comment #16
jenlamptonI was able to make this error message disappear by performing a test to see if $group['fields'] was an array before running a foreach over it. (Please note making the error message disappear is not necessarily a good idea! It will prevent you from noticing which modules are passing poor arguments as you add them in the future.)
patch attached.
Comment #17
MGParisi commentedtesting, works good to solve the issue.
If you want to warn the developer of an issue thats one thing. Send a user a warning for something that works great is another..,. The fix breaks nothing and as far as I can see I have no issues. I have a ton of modules so I cant narrow it down.
Comment #18
MGParisi commentedDuplicate, I marked the other one as Duplicate... but heres the link for more info
http://drupal.org/node/168045
Comment #19
doc2@drupalfr.org commentedMGParisi, in #18 you meant http://drupal.org/node/186775 is a duplicate with more infos. But indeed, the patch to test lies here in #16.
EDIT 2008-09-30: The patch seems to work for me. Thanks
Comment #20
krisvannest commentedIs this patch now included in 5.x-1.x-dev from 2008-Sep-18?
My site also experiencing same error message as above but also with serious slowdowns since upgrading to the latest CCK 5.x-1.9-- so much that my website finally stopped and returned MySQL connection error to visitors, and while trying to do an SQL backup my host reported, "I think part of the problem was that there were a lot of locked queries running on that database, which was preventing the dump from completing."
I looked up how-to-do-patches in Drupal.org and not really advanced enough myself to do apply them.
Comment #21
krisvannest commentedArgh, scrap this comment... looks like I still have web server "premature end of script" errors, even without the "fielgroup" module enabled.
---original text
FYI in case it helps trouble shooting-- after researching these posts, I decided to test enabling/disabling the "fieldgroup" part of CCK and so far, so good.
Before I disabled the "fieldgroup" I received the following server errors every time I visited a page that used CCK and Views:
[Mon Sep 29 05:58:54 2008] [error] [client xxx] Premature end of script headers: /home/xxx/public_html/index.phpAfter disabling "fieldgroup" module (submodule?), but leaving CCK and Views modules enabled, I don't receive these errors anymore.
Comment #22
burlap commentedI have disabled and reenabled all modules on my test site and seems that comment module is responsible for this error (at least this was the first module that triggered the error). I don't have time to look at the code right now though.
Comment #23
featherbellyI am having this same problem creating groups and adding imagecache and node reference fields to them. Have added the fix mentioned above (#3) to 'cck/fieldgroup.module' on line 394 as follows:
Comment #24
j0rd commentedI'm having the same issue. Applied the patch in #23 and it went away.
As for the array not being populated, I added my field group after I had already created quite a few nodes. All but 1 of my nodes, do not have any fields in this fieldgroup populated yet, which might be why this error is poping up.
Cheers,
JOrdans
Comment #25
mofdi2 commentedin CCK filedgroup.module
replace
lign 394:
foreach ($group['fields'] as $field_name => $field) {
with:
if (!empty($group['fields'])) foreach ($group['fields'] as $field_name => $field) {
Comment #26
Anonymous (not verified) commentedUnhappy with hacking up the core code I went and played with my database. Turns out, when I changed the user id in {node} to 1, the node fixed itself, which made me think. Some users had been deleted from our site and their nodes where still there. User 10 for instance was gone, so I replaced all uid 10 with 1 in my database. Problem solved, no hack needed.
Comment #27
benstallings commentedThank you for this observation, bruceclothier. I found the same thing in my database.
Comment #28
karens commentedThe D5 version is no longer being supported. Sorry.