I have a nodereference field that's marked for sync. The referenceable values are defined by a specific content-type, which is language enabled with synchronization.

When creating a new translated node with the nodereference field described above, the translated nid of the referenced value isn't gathered and so the value of the nodereference field isn't synchronized at node creation time. I think this problem occurs, because when creating a new node translation, the function i18nsync_prepare_translation() is only copying the fields from the source to the translated node. So the nodereference field has no chance to get the nid of the translated reference node, like it is going when updating a already existing node translation. So I think the function i18nsync_node_translation_nodereference_field() should also be used when creating a node translation and not only if we are updating a node translation.

Example:

I have a content type product with a nodereference field additional_prices refering to nodes of the content type additional_price, which is language enabled with synchronization.

I create a additional price 500GB HardDrive and translate it to the german node: 500GB Festplatte
I create a product-node Computer with the selected additional_price 500GB HardDrive.

Additional Prices:
- 500GB HardDrive (en)
- 500GB Festplatte (de)

Products:
- Computer:
- Additional Prices
- 500GB HardDrive

Now i want to translate the Computer-node to german and so the additional price 500GB HardDrive should also be translated to 500GB Festplatte, but this doesn't work because of the described problem.

I've currently adressed this issue by rewriting the function:

/**
 * Prepare node translation. Copy over sincronizable fields.
 */
function i18nsync_prepare_translation(&$node, $source, $field_list) {
  foreach ($field_list as $field) {
    if (empty($source->$field)) continue;
    switch ($field) {
      case 'taxonomy':
        // Do nothing, this is handled by the i18ntaxonomy module
        break;

      default:
        $node->$field = $source->$field;
        break;
    }
  }
}

to

/**
 * Prepare node translation. Copy over sincronizable fields.
 */
function i18nsync_prepare_translation(&$node, $source, $field_list) {
  foreach ($field_list as $field) {
    if (empty($source->$field)) continue;
    switch ($field) {
      case 'taxonomy':
        // Do nothing, this is handled by the i18ntaxonomy module
        break;

      default:
      	// Collect info on any CCK fields.
  		$content_fields = _i18nsync_cck_fields($source->type);
  		
  		if (isset($content_fields[$field]) && isset($source->$field)) {
      		switch ($content_fields[$field]['type']) {

       			case 'nodereference':
          			i18nsync_node_translation_nodereference_field($source, $node, $field);
          			break;

        		default:
          			// For fields that don't need special handling.
          			$node->$field = $source->$field;
      		}
    	}
    	else
    	{
    		$node->$field = $source->$field;
        	break;
    	}
    }
  }
}

or have I missed anything concerning this issue?

CommentFileSizeAuthor
#2 i18sync-nodereference-931116.patch938 bytesstijnd
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

iMiksu’s picture

Status: Active » Needs work

Hi! I can confirm this issue and the function rewrite above works fine for me.

Set priority to "Major", since this is part of module´s functionality. Not critical because this issue occurs when using multilingual node references.

stijnd’s picture

This worked perfect for me, thanks seehat.

I've created a patch for this one.

8ballsteve’s picture

Thanks for creating this patch - works like a charm!

Awesome

seehat’s picture

Priority: Normal » Major

I'm pleased to hear, that the rewrite is working for others too.

I set priority to major like iMiksu recommended.

HnLn’s picture

sub

liquidcms’s picture

any chance of getting this committed?

FiNeX’s picture

The patch works fine! I suggest to commit it.

Thanks!

joseph.olstad’s picture

Status: Needs work » Closed (outdated)