Problem/Motivation

After importing node references, a node id is displayed in the imported field, but the node is not referenced. During the import process, the referenced nid is assigned to the incorrect part of the $node structure.

    [field_featured_questions] => Array
        (
            [und] => Array
                (
                    [0] => Array
                        (
                            [nid] => 3362
                        )

                )

            [0] => Array
                (
                    [nid] => 3696
                )

        )

It should look like this:

    [field_featured_questions] => Array
        (
            [und] => Array
                (
                    [0] => Array
                        (
                            [nid] => 3362
                        )

                )

        )

Proposed resolution

Apply the attached patch or re-reference the node id manually through the node edit interface.

Remaining tasks

Please review the patch. I opted to use the field API instead of $node->language, since the node reference field may have multiple languages. Because multiple languages for a node reference may be rare, I left complete support for multiple languages for a later date.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

danielb’s picture

Status: Active » Fixed

I have committed your patch. Thanks.

If you think there is more to do please start a new thread. However, from my understanding of http://api.drupal.org/api/drupal/modules%21field%21field.multilingual.in... when the third parameter is supplied (as is the case in your patch) we never get an array of languages, only one language (or FALSE if no language exists - though I can't imagine how that would happen since 'und' is used by default).

danielb’s picture

Status: Fixed » Active

actually if you don't disagree with what i've said, perhaps we should remove the TODO ?

hedinfaok’s picture

You are absolutely correct, an array will not be returned in this case. I pulled and created another patch.

  • Removed the TODO
  • Changed $langcodes to $langcode to be consistent with core style

BTW, thanks for making it easy to contribute on this one.

danielb’s picture

Status: Active » Fixed

Cheers. Patch seems to be diffed in reverse so I applied the changes manually.

hedinfaok’s picture

Ach, stupid mistake. Thanks again.

Status: Fixed » Closed (fixed)

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