Need to investigate why CCK is throwing foreach() errors and/or SQL errors when adding new or existing fields to content types....

CommentFileSizeAuthor
#20 relevant_content_cck.patch2.51 KBtseven

Comments

bribiz’s picture

I'm also have the same error in 5.x version. This error occurs on the page that is attempting to display the CCK field. Let me know if I can assist further.

# warning: Invalid argument supplied for foreach() in /chroot/home/mydir/mydomain/html/sites/all/modules/relevant_content/relevant_content_cck/relevant_content_cck.module on line 99.
# warning: Invalid argument supplied for foreach() in /chroot/home/mydir/mydomain/html/sites/all/modules/relevant_content/relevant_content_cck/relevant_content_cck.module on line 211
nicholasthompson’s picture

Interesting...

Although I think this is slightly different. My errors were in CCK's content.module whereas yours are inside my module.

Cheers for bringing this up though!

geverest’s picture

I'm having the exact same issue, in that the error is coming from the Relevant Content module cck function.

One of my users is reporting the issue and it seems it might be happening from using the preview without saving and then trying to add content to another cck field. Although I am unable to duplicate it.

On the other hand, to fix it, I simply remove all of the entries my user has placed in the taxonomy field and enter one single term into the taxonomy field (I require at least one entry) and save. At that point the problem goes away and I can do anything I want to the page.

Anonymous’s picture

Version: 6.x-1.x-dev » 6.x-1.4

I'm seeing foreach errors as well but for line 226 of the relevant content CCK module. Subscribing.

Update: I noticed that I only get the foreach error when the relevant content field is enabled to display one the teaser which I'm displaying in a view I created. When I click through to the node there are no errors. For the moment I have hidden the relevant content field from the teaser view which is at http://learnbythedrop.com/drops.

Update 2: I have narrowed down the instances when the error occurs even further. It appears that the error is being thrown when a node is displayed that has no relevant posts associated with it. I'm seeing the error thrown on the post at http://learnbythedrop.com/drop/70. It just so happens that the teaser for the same post was shown in the view that I reference earlier.

dropchew’s picture

Hi there, I had the same error as nicholasThompson, in cck instead of relevant content.

warning: Invalid argument supplied for foreach() in D:\xampp\htdocs\demo\sites\all\modules\cck\content.module on line 1270. This error repeats for each return results.

I notice this only happens when I tried to display as teasers. Where'as when displaying as full nodes, I get a whole "page not available/The connection to the server was reset while the page was loading" error. It working fine when displaying as title and title link.

Drupal 6.6
CCK 2.1 and latest dev (2008-Dec-04)
Relevant content 6.14 and latest dev (2008-Nov-07)

nicholasthompson’s picture

dan_aka_jack’s picture

Status: Active » Needs review

Hi there,

I was getting the following error:

warning: Invalid argument supplied for foreach() in /home/jack/workspace/peckhampower/trunk/sites/all/modules/relevant_content/relevant_content_cck/relevant_content_cck.module on line 228.

As awakenedvoice mentioned in comment #4, it seems that the error is generated when a node has a unique tag (i.e. a tag which is only applied to the current node). I did a bit of tinkering and it turns out that the variable $element['items']['#item'] is null when the error occurs. So I've added a quick if statement to test if the $element['items']['#item'] variable is set before continuing with the foreach statement.

This is what lines 227 to 230 in relevant_content_cck.module currently looks like in version 6.x-1.4 of the module:

    foreach ($element['items']['#item'] as $delta => $item) {
      $items_output .= '<div class="field-item '. ($count % 2 ? 'odd' : 'even') .'">'. theme('relevant_content_cck_field_format_'. $format, $item) .'</div>';
      $count++;
    }

I have replaced the code above with the following code:

  if ($element['items']['#item']) {
    foreach ($element['items']['#item'] as $delta => $item) {
      $items_output .= '<div class="field-item '. ($count % 2 ? 'odd' : 'even') .'">'. theme('relevant_content_cck_field_format_'. $format, $item) .'</div>';
      $count++;
    }
  }

i.e. I've simply wrapped the foreach loop in an if statement.

My modification seems to have fixed the problem for me. I haven't yet noticed any side-effects.

my.wahyu’s picture

I have been activied All CCK MODUL 28 Feb 2009, here .. is my module

Content 6.x-2.1 Allows administrators to define new content types.
Required by: Content Copy (enabled), Content Permissions (enabled), Fieldgroup (enabled), Node Reference (enabled), Number (enabled), Option Widgets (enabled), Text (enabled), User Reference (enabled)

Content Copy 6.x-2.1 Enables ability to import/export field definitions.
Depends on: Content (enabled)

Content Permissions 6.x-2.1 Set field-level permissions for CCK fields.
Depends on: Content (enabled)

Content Templates 6.x-1.0 Create templates to customize output of teaser and body content.

Fieldgroup 6.x-2.1 Create display groups for CCK fields.
Depends on: Content (enabled)

Node Reference 6.x-2.1 Defines a field type for referencing one node from another.
Depends on: Content (enabled), Text (enabled), Option Widgets (enabled)

Number 6.x-2.1 Defines numeric field types.
Depends on: Content (enabled)

Option Widgets 6.x-2.1 Defines selection, check box and radio button widgets for text and numeric fields.
Depends on: Content (enabled)
Required by: Node Reference (enabled), User Reference (enabled)

Text 6.x-2.1 Defines simple text field types.
Depends on: Content (enabled)
Required by: Node Reference (enabled), User Reference (enabled)

User Reference 6.x-2.1 Defines a field type for referencing a user from a node.
Depends on: Content (enabled), Text (enabled), Option Widgets (enabled)

My blog appears ..error notification
warning: Invalid argument supplied for foreach() in /home/xxxxxxxx/public_html/sites/all/modules/cck/content.module on line 1270.

So ... my file in the server .. I simply change ... like this IT DANGEROUS with Your System?? ..!! Just waiting UPDATE MODUL NOTIFICATION ... mybe can fix this error AUTOMATICALLY

Parse error: syntax error, unexpected ')' in /home/xxxxxx/public_html/sites/all/modules/cck/content.module on line 1270

So I try to upload CCK modul again!!
and then I choose ... only useful module..!!
Hem ..its not easy .. to understanding code .. Learning by doing because
basically I'm a simple auditor from gastia.com

rbgrn’s picture

Same error, different line number, not sure if it makes a difference.

This is with D6.10 and latest CCK

warning: Invalid argument supplied for foreach() in /sites/all/modules/relevant_content/relevant_content_cck/relevant_content_cck.module on line 226.

is the full path of where drupal is installed, I just edited it for my own security.

If I get the error on a node, then I get no relevant content. If I get the error in the admin screens somewhere, then most things still work, I just see this error in red. This is definitely a bug.

rbgrn’s picture

I tried wrapping the foreach in the if statement provided above and that got rid of the error. I recommend that patch.

asb’s picture

Hi,

I'm getting those errors with version 5.x-1.3:

Invalid argument supplied for foreach() in /var/www/drupal/sites/all/modules/relevant_content/relevant_content_cck/relevant_content_cck.module in Zeile 211.

Has someone already tried applying the patch to the D5 version?

Thanks & greetings, -asb

skizzo’s picture

I see the error on line 226 (as reported in #4) using CCK 6.x-2.x-dev built on 2009-04-24

warning: Invalid argument supplied for foreach() in /var/www/drupal/sites/all/modules/relevant_content/relevant_content_cck/relevant_content_cck.module on line 226.

spython’s picture

The bug is still there, even after the patch as described in #7.
If I select the field output as title or full node, it works, if I select to display it as teaser, it's broken.

asb’s picture

Similar/duplicate issues: 354459 (D5) & 451726 (D6).

Greetings, -asb

icenogle’s picture

It didn't work for me either, but I got it working with this:

if ($element['items']['#item'] != "") {
.
.

instead of:

if ($element['items']['#item']) {
.
.

This hasn't been extensively tested, but PHP booleans don't always work out the way you expect them to.

mp’s picture

Priority: Normal » Critical

i got these errors when activating both

warning: Invalid argument supplied for foreach() in path_to_drupal_root_directory\includes\form.inc on line 1200.
warning: Invalid argument supplied for foreach() in path_to_drupal_root_directory\includes\form.inc on line 1200.

i added a field to a cck type and all runs fine, but when i tryed to add the existing relevant content field to another cck field i get this one

user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') SELECT vid, nid, FROM content_type_investmentproperty' at line 1 query: INSERT INTO content_field_relcontent (vid, nid, ) SELECT vid, nid, FROM content_type_investmentproperty in path_to_drupal_root_directory\sites\all\modules\cck\includes\content.admin.inc on line 1527.

i´m using the newest D6 version

mp’s picture

and another one when adding a existing "relevant content" to a cck

user warning: Unknown column 'delta' in 'where clause' query: DELETE FROM content_field_relcontent WHERE delta >= 1 in path_to_drupal_root_directory\sites\all\modules\cck\includes\content.admin.inc on line 1492.

dakku’s picture

yup same here:

Invalid argument supplied for foreach() in /var/www/html/{foo}/relevant_content/relevant_content_cck/relevant_content_cck.module on line 226.

gonna wrap in an IF statement as suggested here:
http://drupal.org/node/331625#comment-1204192

calshei1’s picture

I also used the patch, seems to be working just fine now.

tseven’s picture

Version: 6.x-1.4 » 5.x-1.3
Status: Needs review » Patch (to be ported)
StatusFileSize
new2.51 KB

Here is a simple patch for 5.x-1.3. It may work for other versions. I wrapped each foreach in an if (!empty($items)) statement.

Works for me.

Hope this makes it into the code.

asb’s picture

Hi,

thank you the patch; with "-p0" option the patch applies cleanly on D5.

On D6 it fails ("Hunk #1 FAILED at 96. ... Hunk #2 FAILED at 208")

Greetings, -asb

asb’s picture

Hi again,

any progress on this issue?

Thanks & greetings, -asb

..............................................’s picture

thanks, this finally solved this problem for me.

metastate’s picture

I had several of the following errors in my server log:

PHP Fatal error: Call to undefined function relevant_content_cck_content_is_empty() in .../sites/all/modules/cck/content.module on line 906

I think the error was being triggered when new content was being created, with a new taxonomy term (using tags).

Applied the fix suggested in comment #7, ran a couple tests, error seems to have gone away for now.

echoz’s picture

Running Drupal 6.16 + Relevant Content v6.x-1.4

There's 3 issues in the queue for "Invalid argument supplied for foreach" errors, on different files. I think they're all related to the cck field. I just installed the module and after adding a cck field, saving the first screen, I get an Invalid argument supplied for foreach on form.inc line 1207. It is unclear to me from reading through these 3 issues what, if any are the correct fix for the form.inc error. I did not see that the dev version addressed this.

I am thrilled to find this awesome module, and hope to be able to use the cck feature. Any clarification?

metastate’s picture

Actually, even after I used the fix suggested in #7, the site was still throwing the error. Didn't have time to troubleshoot further. I decided to make my own related content block with Views in the end.

Tutorial I used as a starting point: http://drupaleasy.com/blogs/ryanprice/2008/06/using-views-2-drupal-6-cre... (good tips in the comments too, I found #26 and #48 really helpful)

echoz’s picture

That's what I did (sorry for not posting this), also written about here - http://drupal.org/node/65375

drurian’s picture

I got errors in 6.x-1.4 version, so I updated to latest dev version and the errors seem to have gone away.

nicholasthompson’s picture

Issue summary: View changes
Status: Patch (to be ported) » Closed (outdated)

Closing this as D5 and 6 are not support anymore + a fix for D7 for a similar bug has been committed.