Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi
this is a patch that allow to synchronize nodereference fields with the corresponding translations (if they exists).
info about patched module:
; $Id: i18nsync.info,v 1.1.2.3 2007/06/18 23:06:46 dww Exp $
name = Synchronization
description = Synchronizes content translations
dependencies = i18n translation
package = Multilanguage - i18n - experimental
; Information added by drupal.org packaging script on 2007-10-30
version = "5.x-2.2"
project = "i18n"
datestamp = "1193766006"
patch:
--- i18nsync.module.orig 2007-06-06 13:54:18.000000000 +0200
+++ i18nsync.module 2008-04-04 13:08:46.000000000 +0200
@@ -163,16 +163,46 @@ function i18nsync_node_translation($node
}
}
break;
- default: // For fields that don't need special handling
- if (isset($node->$field)) {
- $translation->$field = $node->$field;
- }
+ default: // For other fields
+ if (isset($node->$field) && $_field = $node->$field) {
+ // For nodereference fields !IT'S RAW METHOD, MAY NEED REVIEW!
+ if (isset($_field[0]['nid']) && $_field[0]['nid'] != $node->nid ) {
+ i18nsync_node_translation_referenced_node(&$node, &$translation, $field);
+ } else {
+ // For fields that don't need special handling
+ $translation->$field = $node->$field;
+ }
+ }
}
}
node_save($translation);
}
/**
+ * Node reference that may have translation
+ *
+ */
+function i18nsync_node_translation_referenced_node(&$node, &$translation, $field) {
+$translation->$field = array();
+ $_field = $node->$field;
+ foreach ($_field as $key=>$reference) {
+ if ($referenced = node_load($reference['nid'])) {
+ // This content type has translations, find the one
+ if (variable_get("i18n_node_$referenced->type", 0) && isset($referenced->translation[$translation->language])) {
+ array_push($translation->$field, array('nid'=>$referenced->translation[$translation->language]->nid));
+ drupal_set_message(t('%title referenced node has been synchronized to %language translation',array('%title'=>$referenced->title, '%language'=>$translation->language)));
+ } else {
+ // Reference without translation, just copy the nid
+ array_push($translation->$field, $_field[$key]);
+ }
+ } else {
+ // False reference nid, just copy the nid
+ array_push($translation->$field, $_field[$key]);
+ }
+ }
+}
+
+/**
* Node attachments that may have translation
*
*/
I also give in attached files a bundled patch of this add-on + "automatic update path after synchronizing taxonomy" (see http://drupal.org/node/237546#comment-779300)
Tests and reviews are welcome!
Comment | File | Size | Author |
---|---|---|---|
#4 | i18n-242601-4.patch | 3.75 KB | dasjo |
#3 | i18n-242601-3.patch | 3.09 KB | dasjo |
i18nsync.pathauto_nodereference.patch | 3.67 KB | adrien.gibrat | |
i18nsync.nodereference.patch | 1.98 KB | adrien.gibrat |
Comments
Comment #1
Jose Reyero CreditAttribution: Jose Reyero commentedThis looks good. However I think we could reuse the code for attached nodes which is quite similar.
Also, to avoid future headaches, it should handle the case of cck fields with multiple values.
Comment #2
kharbat CreditAttribution: kharbat commentedis there a similar patch for drupal 6 ??
Comment #3
dasjonedjo and me worked on a solution for this issue regarding the translation of nodereferences in i18n, drupal 6
jose, so we followed your advice, reused the attached nodes sync code.
so we have a helper function i18nsync_node_translation_reference_field which is used by i18nsync_node_translation_attached_node and i18nsync_node_translation_nodereference_field
i attached the patch, it's actually my first one, so i hope it works fine ;)
Comment #4
dasjothe same patch in cvs diff -up format
Comment #5
Jose Reyero CreditAttribution: Jose Reyero commentedThis one looks much better
Just need someone else to give it a try and tell me it works.
@nedjo, if you are around, feel free to commit.
Comment #6
Jose Reyero CreditAttribution: Jose Reyero commentedI'm thinking let's speed up the process.
As I've been committing some other improvements in that module, see changelog, I've also committed this one, so you don't need to update it again.
If this breaks anything, someone will let us know :-)
Comment #8
Dubs CreditAttribution: Dubs commentedWe have a CCK Node reference which referencing bi-lingual versions of a node. If we have a view which uses the node reference field as an exposed filter, then select a node and change language, then we get the following error: -
An illegal choice has been detected. Please contact the site administrator.
You can see the problem at http://plwm.nmaltd.com/events/gallery
Just pick an event from the dropdown (the node reference field) and then click "Cymraeg) in the top-right and the error should be displayed.
Is there anything that i18n can do about this, or does the problem lie outside the scope of this module?
Comment #9
GN CreditAttribution: GN commentedi18nsynching of nodereferences seems to work only for already existing nodes, not for a fresh new translation before first saved. It looks like this:
This behavior is similar to an imagefield issue #533228: i18nSynchronization of imagefields using image_fupload widget works only for existing nodes, not for fresh new translations.
Comment #10
orjantorang CreditAttribution: orjantorang commentedIn my case a translation action gives no opportunity to check (I use checkboxes) any nodereferences, not even when I edit the new node.
I can see the title of the nodereference field but no form fields. In the database field content_field_... there is a NULL value stored. I changed this value
manually and in the view for the node I can now see the nodereferences, but still in edit I can't see any form fields.
I don't know the status of this project, but I have read #573548: Open i18nsync to modules (Open i18nsync to modules) and I think that is a good idea, but also a standard choice in in18n like http://drupal.org/project/node_clone, would be nice.
/Örjan
Comment #11
askibinski CreditAttribution: askibinski commentedsubscribe
Comment #12
bibo CreditAttribution: bibo commentedsubscribe.
It still seems unclear to me how this should work in the current 1.5 i18nsync version. Apparently it syncs the referenrences' translations on some occasions, but generally it doesnt.
Comment #13
colanSubscribing.
Comment #14
rp7 CreditAttribution: rp7 commentedSubscribing, this is pretty critical...
Comment #15
varac CreditAttribution: varac commentedSubscribing, we have the same problem here (6.x-1.7) and think this is very important to fix !
Comment #16
blaiz CreditAttribution: blaiz commentedActually this works for me. I'm synchronizing node references across translations. When I edit the English language one, and save, on the Italian translation, it will search for translated references and save the translated one, if not all referenced pages have been translated, then it will save the English ones instead, which is what I want.
Problem is, when I want to edit the Italian translation then, when I click on Save, it shows an error message stating "Name of the field: this post can't be referenced." for all the ones that reference English pages.And if I delete the English references here, since it's synchronized, it deletes them on the other languages as well.
Is there a way to override this? to force node reference to save even if some references link to another language?
Comment #17
jphil CreditAttribution: jphil commentedThis is really annoying and needs to be fixed ASAP....
Comment #18
Bartezz CreditAttribution: Bartezz commented+999
Subscribing
Comment #19
Seighaus CreditAttribution: Seighaus commentedsubscribing
Comment #20
zilverdistel CreditAttribution: zilverdistel commentedThis is my situation:
- node type A refers to node type B (and vice versa).
- node type A is language neutral
- node type B can be Dutch (nl) or English (en).
When I save node of type A, I get the error
Saving a node of type B succeeds.
Comment #21
Cameron Tod CreditAttribution: Cameron Tod commentedIs there a similar patch against 6.x-1.7?
Comment #22
stevenator CreditAttribution: stevenator commentedsubscribing
Comment #23
screenage CreditAttribution: screenage commentedsubscribing
Comment #24
ducdebreme CreditAttribution: ducdebreme commentedsubscribing
Comment #25
pedrospsubscribing
Comment #26
zilverdistel CreditAttribution: zilverdistel commentedwe fixed our problem by changing the content negotiation rules on admin/settings/language/i18n to "All content. No language conditions apply." This is just a temporary quickfix that works for us.
Comment #27
YK85 CreditAttribution: YK85 commentedsubscribing
Comment #28
Seighaus CreditAttribution: Seighaus commentedMy Problem (attach language neutral content to translatable content) was solved by this solution: http://drupal.org/node/855102#comment-3404492
Except I don't use a block but node attachment to attach my content.
I hope this helps some of you as well!
Comment #29
zeutyAnything new on this issue?
Comment #30
shreeni2 CreditAttribution: shreeni2 commentedsubscribing
Comment #31
slucas CreditAttribution: slucas commentedI've lost some time to understand that this patch have been already applied to current version of i18nsync.
Furthermore to allow node reference of different language to be referenced in a node reference field use view and node language filter to achieve the result you want.
Select the view you've just done in the node reference field settings to select appropriate nodes.
This was quite challenging for me to understand this.
So I write it down here to give clue to others.
Comment #32
bvanmeurs CreditAttribution: bvanmeurs commentedSolution here: http://drupal.org/project/i18n_node_reference
Comment #33
joseph.olstad