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
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

dakku - September 17, 2009 - 12:56

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

nicholasThompson - September 17, 2009 - 14:42

There should be a fix for this committed recently... Can you try (cleanly) updating?

#3

nicholasThompson - September 17, 2009 - 14:42
Status:active» needs review

Setting appropriate status

#4

dakku - September 24, 2009 - 08:49
Status:needs review» fixed

seems fine in the latest cvs

#5

System Message - October 8, 2009 - 08:50
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.