Just upgraded CCK to 4.7.0 21/08/06 release. The upgrade went fine, database upgrade looked alright except I was getting this php error in logs:

Invalid argument supplied for foreach() in /home/bsix/public_html/modules/contrib/cck/content_views.inc on line 24.

It wasn't affecting anything, just showing up in the logs, under PHP5.

This is the section just around line 24

 $formatters = array();
    foreach ($field_types[$field['type']]['formatters'] as $name => $info) {
      $formatters[$name] = t($info['label']);
    }

I'm pretty sure it's because I created a date field, then disabled the number module. When I re-enabled the number module the error went away.

However, there's no place in the UI to delete fields once you've made them - you'd have to do it in the database. Since number.module etc. are all optional, then it ought to be possible to delete fields from them when they're deactivated (or just in general to keep things tidy) via the content types administration screen, or alternatively leave the fields there but have content_views.inc not look for them so errors aren't produced on deactivation.

Not sure if this is really a bug report or a feature request, but couldn't find it elsewhere.

CommentFileSizeAuthor
#17 content_views.inc_0.patch850 byteskarens
#16 content_views.inc.patch927 byteskarens

Comments

kevinwalsh’s picture

Hi, I'm getting the same error with the new cck (28/8/06) that i installed this morning. However, i don't think i disabled any of the associated modules like number or text or date.

mh86’s picture

same error - always when I empty the cache

ncatchpole’s picture

I'm now getting this error again with the modules reactivated.

ncatchpole’s picture

Priority: Minor » Normal

raising priority since this is applying to cck in general now.

My modules page is also broken every time I change a setting - going back to admin allows the module to be restored, but it's white screen - "invalid argument.... headers already sent" if I enable or disable anything.

karens’s picture

I'm also getting this message. After some work trying to figure out what was triggering it and how to get rid of it, I came up with the following process:

FYI - the message is erratic because it only gets triggered when the views cache is cleared.

1) Go to content > content types
2) Pull up each of your content types.
3) For each type, go to the manage fields tab.
4) Look for fields that have a blank value under the column heading 'Type'.
5) Those are fields that are incompletely defined or where the module is disabled, or something else is wrong with them.
6) Remove each of those fields (they won't work anyway).

That should fix the problem.

karens’s picture

I should also say if you have valuable data in those fields, don't remove them or you will lose your data. Instead re-enable the module or update it or whatever else needs to be done so that it is functional again.

Robardi56’s picture

The only fields with no value under type are the "title" field and taxonomy fields.
No way I can / want to remove them.

Brakkar

karens’s picture

Nope, you can't remove them anyway. If that didn't show anything, then you have a field module enabled that does not have the formatters defined. Do you have the latest versions of all the field modules? Are any of your fields using anything other than the core fields? One way or another you're missing formatter info (that's what's on that line).

karens’s picture

One thing you can do is open up each field module you are using in a text editor and scan through it for function names that use the word 'formatter' (there are 2, formatter_info and formatter). You must have one or more modules that are missing those functions.

pulpzebra’s picture

I get the same error ONLY when Views module is activated/deactivated.
Also, it might be an issue related to content types created with previous versions of CCK. When the scripts triggers the content_views_table function in content_views.inc it performs a foreach on the $field_types ... formatters value. In my case, there was no value for that, then, php issued a warning message.

If this is the case (I'm not a CCK developer) I suppose that

+ if ($field_types[$field['type']]['formatters'])
+   { 
    foreach ($field_types[$field['type']]['formatters'] as $name => $info) {
      $formatters[$name] = t($info['label']);
+    }

putting the foreach statement under a condition solves this issue.

karens’s picture

If you're getting the message there is something in your configuration that is not right. The message goes away when you disable views because the function only gets called when views is enabled, but it's not a views problem. You could make the message not display as indicated above, but that just muddies the waters. Anyone who is seeing this message has something that needs to be fixed in their setup, so I think it's better to get it fixed than to hide the message.

I've run into this on several setups and the problems in each case were slightly different and fixed in different ways, so I thought it would help to summarize here:

1) To test for the problem, clear your cache by going to the modules page and saving it, then go to admin/views. The first time you go there after clearing your cache you will see this error, if you have it.

2) The problem may be that you have enabled a cck field module that does not yet have the formatters set up. If so, the module must be disabled or updated. I ran into this with the imagefield module (it may be updated by now, but the version I had installed was not). To find out whether this is the problem, make sure you have the latest version of all field modules, then check for the error (see above). If there is no error, you have gotten it fixed. If there is still an error, open each field module up in a text editor and look for a function with the name 'formatter' in it. If you find a module without any function with that name, that is your problem.

3) The problem may be that you have a field already created in your database that is dependent on a field module that has been disabled or that is not correctly configured. To determine that, go to content/content_types, pull up each content type, then pull up the manage fields screen for each type. Look for any fields that have nothing displayed under 'type'. If you find any, either remove them or enable the module (after making sure it has the formatter function as noted above). Then check again to see if the error is fixed.

4) You may have a field that was previously defined but no longer being used that depends on a module that has not been updated or is not installed. To find this you need to view the database using something like phpmyadmin. Browse the file node_field. Look at the column 'global settings'. If you see any fields that have something like ' a:0:{}' in that column, they are problems. Look and see what field type they are and make sure that module is installed and updated. Then check again to see if the error is fixed.

One of the above steps should fix the problem, or at least tell you which field module is causing the error.

karens’s picture

Title: invalid argument foreach when modules deactivated. » invalid argument foreach in content_views.inc on line 24.

Changing the title to make it easier for others to find...

pulpzebra’s picture

Such an explanation was what I was after. In fact I believe that when I first came into this issue on my production site, the reason for that could have been the missing installation of the weburl module. However, this warning has also appeared on a brand new drupal 4.7.3 installation with CCK 4.7.0 and Views 4.7.0 (with no cck fields and content types defined). I knew that putting the foreach statement under a condition might not be the best thing ever, but then the problem should have another explanation apart a corrupted cck configuration.

patrickharris’s picture

I'm having the same problem.

karens’s picture

I hadn't thought about the new installation with no fields defined, but you're right that it will probably throw this error in that case until a field is defined (when the error will disappear), so it does make sense to change the code as suggested above.

It was good to have a warning that you had a configuration problem so you could fix it, but it can't be done at the cost of creating errors in new installations :-)

Need to make this into an official patch and mark it as such.

karens’s picture

Status: Active » Needs review
StatusFileSize
new927 bytes

Here's the patch...

karens’s picture

StatusFileSize
new850 bytes

Rethinking this, I think I need to be sure $formatters still exists as an array if there are no fields, so I changed the patch slightly...

ncatchpole’s picture

The module causing this issue for me was number.module - which had an a:0:{} in the column.

I disabled and removed, then deleted from node_field and the row in system table, flushed cache and it seems to have gone. Thanks for working out what the problem was and sorting it out so quickly!

csc4’s picture

For me - the answer seemed to be to convert content-* to content_* though there didn't seem to be any warning in the readme that you'd need to.

patrickharris’s picture

Thanks Karen,

Once I saw how small the patch was, I applied it by hand - and it solved my problem.

Good work!

marcoBauli’s picture

works just fine here too, thank you!

karens’s picture

Status: Needs review » Reviewed & tested by the community

I'll go ahead and mark it RTBC

thierry_gd’s picture

Had the same problem. Applied the patch. Work perfectly for me --> patch has to be applied

stanbroughl’s picture

i love this patch!

enky’s picture

is this patch committed to cck 4.7.0?

thierry_gd’s picture

Not yet, but I hope soon because it works perfectly

karens’s picture

Status: Reviewed & tested by the community » Fixed

This fix has been committed to 4.7 version. I see that formatters have not yet been added to cvs. I'll open another issue for that.

Anonymous’s picture

Status: Fixed » Closed (fixed)