Invalid argument foreach() relevant_content_cck.theme.inc line 26
dakku - September 17, 2009 - 11:47
| Project: | Relevant Content |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Description
Hi mate, sorry to point out another watchdog error:
Invalid argument supplied for foreach() in /../relevant_content/relevant_content_cck/theme/relevant_content_cck.theme.inc on line 26.cheers

#1
I think this tends to happen when there are no related nodes.
perhaps you should wrap your foreach loop with a check like this in line 26:
<?php
// make sure we have something for the loop to avoid Invalid argument foreach() errors
if($num_items > 1){
// Loop over all the items and create the field output
foreach ($element['items']['#item'] as $item) {
$attributes = array('class' => 'field-item ' . ($count % 2 ? 'even' : 'odd'));
// Append a "first" class to the row
if ($count == 0) {
$attributes['class'] .= ' first';
}
// Append a "last" class to the row
if ($count == $num_items - 1) {
$attributes['class'] .= ' last';
}
// Depending on the type, render a field
switch ($type) {
default:
case 'default' :
$result = l($item['title'], 'node/'. $item['nid']);
break;
case 'plain' :
$result = check_plain($item['title']);
break;
case 'teaser' :
case 'full' :
$result = node_view(node_load($item['nid']), ($type == 'teaser'));
break;
case 'token_full' :
case 'token_teaser' :
// Run a token replace on the content
$types = array('global' => NULL, 'node' => node_load($item['nid']));
$result = token_replace_multiple($token_pattern, $types);
break;
}
// Generate the field
$output .= '<div'. drupal_attributes($attributes) .'>'. $result .'</div>';
$count++;
}
}
?>
#2
There should be a fix for this committed recently... Can you try (cleanly) updating?
#3
Setting appropriate status
#4
seems fine in the latest cvs
#5
Automatically closed -- issue fixed for 2 weeks with no activity.