CNR is giving a PHP Notice when adding new content with a reference to an existing node which has no back references:
"Notice: Undefined index: und in corresponding_node_references_insert() (line 30 of ...\sites\all\modules\cnr\corresponding_node_references.crud.inc)."

This doesn't seem to prevent the creation of the back reference, but the notice message is confusing to users.

I've fixed this locally by replacing

if ($referenced_node->{$away_field}[$lang][0]['nid'] == NULL) {

with

if (array_key_exists($lang, $referenced_node->{$away_field}) == FALSE || $referenced_node->{$away_field}[$lang][0]['nid'] == NULL) {

Comments

rfay’s picture

Title: PHP Notice Undefined Index when adding new content » "Undefined index: und in corresponding_node_references_insert()" when adding new content
Version: 7.x-4.1 » 7.x-4.x-dev

I got the same error when adding referenced node:

Notice: Undefined index: und in corresponding_node_references_insert() (line 34 of /home/rfay/workspace/support/sites/all/modules/cnr/corresponding_node_references.crud.inc).
damienmckenna’s picture

Just ran into this.

AgaPe’s picture

the same

czigor’s picture

Status: Active » Fixed

Thanks for the fix, gtill. Committed it.

ClaudeS-1’s picture

FYI, getting the same, but from the update function instead of the insert function.
Using 7.x-4.x-dev from 2011-May-14

Am editing nodes which should have back-references to each other, but I think another language-related bug (http://drupal.org/node/1159304) is stopping it all from working.

Notice: Undefined index: und in corresponding_node_references_update() (line 154 of /httpdocs/sites/all/modules/cnr/corresponding_node_references.crud.inc).
Warning: Invalid argument supplied for foreach() in corresponding_node_references_update() (line 154 of /httpdocs/sites/all/modules/cnr/corresponding_node_references.crud.inc).

Status: Fixed » Closed (fixed)

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

tiyberius’s picture

Version: 7.x-4.x-dev » 7.x-4.1
Status: Closed (fixed) » Active

I'm using Drupal 7.8-dev and CNR 7.x-4.1, and I'm getting the error described in the original post. I followed gtill's directions ...

I've fixed this locally by replacing
if ($referenced_node->{$away_field}[$lang][0]['nid'] == NULL) {

with
if (array_key_exists($lang, $referenced_node->{$away_field}) == FALSE || $referenced_node->{$away_field}[$lang][0]['nid'] == NULL) {

and the error went away. Looking at comment #4 in this issue (http://drupal.org/comment/reply/1148948#comment-4465060), I thought it had been committed, so I'm thinking that the original if() statement crept back into the latest release somehow?

czigor’s picture

Status: Active » Fixed

It is not in 4.1 yet but only in the dev.

Status: Fixed » Closed (fixed)

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

Frederic wbase’s picture

fixe worked great, thx!

trgreen17’s picture

Brilliant! Thanks so much for the tip. Works perfectly.

Tim

Frederic wbase’s picture

maybe commit it to latest dev?

rv0’s picture

I did it a bit differently..

I think the error originates when the field is empty, so of course it wont find index "und".
So instead of doing array_key_exists:

if (isset($referenced_node->{$away_field}) && $referenced_node->{$away_field}[$lang][0]['nid'] == NULL) {

The && makes more sense to me than using ||

anybody’s picture

Issue summary: View changes

Is it possible to get this into a new stable? The problem still seems to exist and is only fixed in dev? So it's not usable in production even after 3 years!
After this long time it should be testet enough :)

Thanks a lot for the great module!