Download & Extend

CCK Preview Error with Link Field

Project:Link
Version:5.x-1.1
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

I'm getting the following errors when previewing a node:

    * warning: Invalid argument supplied for foreach() in /home/mysite/public_html/dev/sites/all/modules/cck/content.module on line 1113.
    * warning: Invalid argument supplied for foreach() in /home/mysite/public_html/dev/sites/all/modules/cck/content.module on line 1153.
    * warning: Invalid argument supplied for foreach() in /home/mysite/public_html/dev/sites/all/modules/cck/content.module on line 1153.
    * warning: Invalid argument supplied for foreach() in /home/mysite/public_html/dev/sites/all/modules/cck/includes/content.token.inc on line 18.

This is happening with my current site running D6.3, tried it with CCK 6.x-2.0-beta, 6.x-2.0-rc4 and 6.x-2.x-dev but its still returning those errors. I tried doing a fresh install of CCK and re-recreated my fields thinking that this might go away. I also installed two new D6.3 sites with same modules as the current (different database) but the ERRORS STILL PERSIST.

Errors persist on any node type with a link field (versions 6.x-2.2, 6.x-2.3 and 6.x-2.3.1). If I leave the link field blank or disable it the preview problem seems to go away.

If you want to take an actual look to whats happening on my site please go to http://dev.betswire.com/ login as testuser and 123456 as the pw. Create a 'Test Content with Link' then preview that so you can see the error and check whats going on.

Please look into this. Thanks.

P.S to mods: This is not a duplicate post. I have closed the other one for a more clean and concise explanation here.

Comments

#1

i was able to reproduce your error on your site.. I noticed that if you create the post without previewing there are no issues.

I couldn't reproduce these errors on my 6.2 site with a cck link field, when I update I'll see what happens and post back here.

#2

Thanks pathogen. Being able to reproduce will be key to fixing the problem. I've never seen this problem before either, but I think a few others have reported it also.

#3

Thanks pathogen let us know immediately. Drupal 6.2 is also doing fine for me. It started when I upgraded to 6.3. 3 of my sites running D6.3 were able to reproduce these erorrs.

#4

Category:support request» bug report
Status:active» needs review

It'd help if I really read the issue. I wasn't trying Preview, I was just submitting. I reproduced it right away after looking for the right thing.

The trouble is token module building the node while there is no $nid available. The result is an empty node that when CCK tries to get a list of fields, it only gets a boolean FALSE. Please try out this patch and let me know if it solves the problem for you.

AttachmentSize
link_preview_warning.patch 701 bytes

#5

Am getting this 1 out of 1 hunk FAILED -- saving rejects to file link.module.rej

#6

I have applied the patch manually (total newbie here so its best if you could rewrite the patch) but the warning/error still persist when previewing the node.

#7

I see this issue in the 5.x-2.3.1 version as well. Issue only exists on Preview, and only before the node has been submitted - after submitting the node, preview works fine.

I have tried turning off "Allow user-entered tokens" on the field edit admin page, which removes some of the errors, but there are still some errors displaying.

#8

I will keep posting here, rather than creating another issue for the 5.x version, since it looks like it's the same issue for both. Let me know if you'd like me to create a new issue.

The errors that are displaying in 5.x are:

    * warning: Invalid argument supplied for foreach() in /modules/node/node.module on line 521.
    * warning: implode(): Bad arguments. in /modules/node/node.module on line 525.
    * 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 '' at line 1 query: SELECT n.nid, n.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data FROM node n INNER JOIN users u ON u.uid = n.uid INNER JOIN node_revisions r ON r.vid = n.vid WHERE in /includes/database.mysql.inc on line 172.

Site is running Drupal 5.7, CCK 5.x-1.7

#9

When I check "Allow user-entered tokens" when editing the field in the content type, then I just get the exact same error as above, but twice.

#10

I think you have the solution in the patch, it just needs to go into two places.

For 5.x-2.3.1, use this line:

    $node = isset($node->nid) ? node_load($node->nid) : $node; // Necessary for nodes in views.

in the place of this line:

    $node = node_load($node->nid); // Necessary for nodes in views.

At lines 590 and 697.

#11

Here's a patch that applies in both places where tokens are replaced.

AttachmentSize
link_preview_warning.patch 1.2 KB

#12

I'm getting

patching file link.module
Hunk #1 FAILED at 302.
Hunk #2 FAILED at 340.
2 out of 2 hunks FAILED -- saving rejects to file link.module.rej

Nonetheless, I have applied the patch manually and IT WORKED like a charm!

Thank you very much!

#13

Status:needs review» fixed

Great, I've committed to both the Drupal 5 and 6 versions.

#14

I'm hunting around for a fix to a problem that seems to be similar.

I'm using Drupal 5.9 with cck, link, token and auto_nodetitle. I get Invalid argument supplied for foreach() in /xxx/modules/node/node.module on line 561. followed by mysql errors when I submit a cck type with a link field. The error ceases when I turn off the option to allow the usage of tokens in the link field.
Using auto node_title to create the title automatically from tokens doesn't cause the error, making me think the issue is with link module not token module?

I'm trying the patch in #11, replacing lines 590 & 696 since the patch doesn't translate for the 5.x version. Also in the 5.x version the variable is called $node not $token_node as in the 6.x patch, so I changed this and it seems to work.

It looks like there are other posts with this same issue, it's kinda hard to keep track :)

http://drupal.org/node/142286
http://drupal.org/node/283805
http://drupal.org/node/285293
http://drupal.org/node/282305

Hopefully the issue is with link and not token.

Drew

#15

I have the problem evilgenius originally posted:

warning: Invalid argument supplied for foreach() in /home/mysite/public_html/sites/all/modules/cck/content.module on line 1112.
warning: Invalid argument supplied for foreach() in /home/mysite/public_html/sites/all/modules/cck/content.module on line 1152.
warning: Invalid argument supplied for foreach() in /home/mysite/public_html/sites/all/modules/cck/content.module on line 1152.
warning: Invalid argument supplied for foreach() in /home/mysite/public_html/sites/all/modules/cck/includes/content.token.inc on line 18.

It goes away if I disable the token module.

#16

@ keathmilligan,

My understanding is that the issue IS with the link module, but it is within a block of code that tests the token module is active. So disabling token module will appear to fix it, but actually you are simple avoiding using the problematic code, and losing all the great features of token.

Try adding the patch in post 11 to link module, evil genius suggests doing so manually (#12). Here is info on patching http://drupal.org/node/60108.
If it fails to patch just open the .patch file in a text editor and remove lines starting with '-' from the link.module and add lines starting with a '+' to the link.module file. Don't add the actual '+'s

There are line numbers listed within the .patch to help you find where the changes are, and there are also lines that have no '+' or '-' that stay the same, but help you find the location of the change.

HTH

#17

feedback: patch seems to work ...

thanks a lot
momper

#18

I'm still getting the error shown in #15. Something is still broken here.

Edit: I found what was going on. Conflict with another module...

#19

@keathmilligan.

I realize your error is not related to the original thread, but if you fixed it please post how. If it's possible someone else can make the same error appear, do a search for the error message and get to this thread. It is useful to see what helped fix it for you.
Also if there are conflicts it may be worth posting to the relevant module issue queues so the maintainers get a chance to look into it.

#20

Status:fixed» closed (fixed)

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

#21

the patch worked for me.Did it using cygwin.Thank you.

#22

Status:closed (fixed)» reviewed & tested by the community

Confirmed. Patch in #11, manually applied, fixes the problem. Re-rolling patch, may help those for whom #11 didn't apply. Updating (downdating ?) issue to RTBC, since quicksketch still hasn't committed to a release version and this issue needs to be on his radar. :-) Also makes it easier to find for those with the problem.

AttachmentSize
link_preview_warning-285293-22.patch 1.07 KB

#23

Status:reviewed & tested by the community» fixed

Thanks mrtoner.

I'm releasing a new version tonight. :)

#24

Status:fixed» closed (fixed)

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

#25

Version:6.x-2.3.1» 5.x-1.1

Hi all,

I just had the same problem with the Event and Link module. I followed two tips given here. One was to edit my content type fields (manage field) and disabled all fields that use token replacement (click configure in each field). My culprit was the link CCK type.

While that solved some of my issue it did not solve all problems. I edited the link.module (line 697) from this:

$node = node_load($node->nid); // Necessary for nodes in views.

to this:
$node = $node; // Necessary for nodes in views.

I got the idea from here: http://drupal.org/node/142286 and take a look at comment number 8.

I am now trouble free from the preview bug. I hope this helps you as well. If someone would like to create a patch for these modules that would be greatly appreciated. How about fixing this issue even in the older 5.x versions?