I saw this reported for 5.x, not sure what is causing it 6.x

warning: Invalid argument supplied for foreach() in
/Library/WebServer/Documents/drupal/sites/all/modules/cck/content.module on line 1270.

Comments

yched’s picture

Status: Active » Postponed (maintainer needs more info)

Those issues are extremely hard to track down, and are generally caused by 3rd party modules that build invalid nodes.
We've been doing our best to protect cck against those error cases, but if some still show up, there's not much that can be said or done without knowing exactly when and with which node types this happens.

Except disabling all non-cck contrib modules and re-enabling them one by one to see when the error reappears, I have little advice to give...

agerson’s picture

Status: Postponed (maintainer needs more info) » Active

I disabled everything except for the root cck module and I still get the error:

warning: Invalid argument supplied for foreach() in /Library/WebServer/Documents/drupal/sites/all/modules/cck/content.module on line 1270.

markus_petrux’s picture

Have you tried CCK 6.x-2.2?

agerson’s picture

Version: 6.x-2.1 » 6.x-2.2

I just updated to 2.2 and I still get the same error. Its only when logged in as admin. Stranger then that, I have q=node/1 set to be the page displayed when I go to the root /drupal directory in a web browser. I use Login Destination. If I got to http://www.mysite.com/drupal/?q=node/1 I do not get the error, but if I go to http://www.mysite.com/drupal/ which forwards me to http://www.mysite.com/drupal/?q=node/1 I get the error.

blue.moon’s picture

Maybe its because of this, I think module_invoke does not return associative array, does it?

Line 1717
$module_field_types = module_invoke($module, 'field_info');
if ($module_field_types) {

if it returns array then try this.,

$module_field_types = array();
$module_field_types = module_invoke($module, 'field_info');
if ($module_field_types) {

else it is wrong approach to call foreach() on string.

Ether’s picture

subscribe

markus_petrux’s picture

Those that have this problem, please try with CCK 2.2 and specify which line the error is refering to. The one in #2 and in original post is 1270, which an empty line in 2.2, so it's hard to tell where the error happens.

Ether’s picture

Invalid argument supplied for foreach() in \sites\all\modules\cck\content.module on line 1278.
Have this when trying to post comment and Embed and Attachments modules from File Framework are enabled. Using version 2.2, drupal 6.10

markus_petrux’s picture

Marked this issue as a dup: #429044: warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\eResepi\modules\cck\content.module on line 1278.

@Ether: Thanks.

Well, line 1278 in CCK 2.2 lives in _content_field_invoke_default():

  $type_name = is_string($node) ? $node : (is_array($node) ? $node['type'] : $node->type);
  $type = content_types($type_name);
  ...
  ...
  ...
    foreach ($type['fields'] as $field) {  // This is line 1278

The notice means $type['fields'] is not an array, but I tried to analize what could be causing this attribute to be undefined and I couldn't.

It comes from content_types(), and that one gets it from $info = _content_type_info();. If $info['content types'] is not set, then $type['fields'] should be an empty array (no notice should be generated in this case). If $info['content types'] is set, it comes either from a) content cache, o b) built. And here it is hard to see what could be causing malfunction without further debugging.

I would try to print_r() structures here and there and then see where the problem is.

Hard to tell...

agerson’s picture

Same error foe me in 2.2

warning: Invalid argument supplied for foreach() in /Library/WebServer/Documents/drupal/sites/all/modules/cck/content.module on line 1278.

agerson’s picture

print_r($type['fields']); prints:

"Array ( )"

echo $type_name; prints:

"page"

markus_petrux’s picture

Status: Active » Closed (duplicate)

Ok, this is a dup of #319042: foreach() on empty array

Please, read the whole issue. Same error and all cases ended up being caused by something wrong not related to CCK. Probably, the node type assigned to the node is not there or something similar.