When NodeReferrer is used with the i18n, there is some mixup when the referrers nodes are retrieved in nodereferrer_referrers.

i18n rewrite DB queries according to the its selection mode (i18n_selection_mode). Unless i18n filtering has been disabled for the whole site, it means that results of the DB query in nodereferrer_referrers depends on page that triggered the function call.

On a node page (ie. when $node = menu_get_object('node')) returns a non-false value) the filtering mode is set so the query is filtered to return only results sharing the same language as the node. But if the node has no language (ie. Language Neutral), the filtering is done using the current interface language.

On any other page, the results are also filtered using the current interface language. And because the results are then cached when returned from nodereferrer_field, you end up with inconsistent results depending of the language used when the cache was build.

A solution would be to set the i18n selection mode before calling nodereferrer_referrers to either the node language (if any) or 'off' (to disable filtering). That way we can ensure consistent results and avoid relying on the interface language.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pbuyle’s picture

Status: Active » Needs review
FileSize
2.84 KB

The attached patch should set the i18n selection mode to a sensible value. A better approach may be to pass the whole $node object to nodereferrer_referrers() (since we always have it) and set the i18n selection mode from there.

pbuyle’s picture

Title: NodeReferrer should sets the i18n selection mode » NodeReferrer should set the i18n selection mode
Priority: Normal » Major
mvc’s picture

Status: Needs review » Reviewed & tested by the community

works perfectly for me. i'm using it in combination with #671406: NodeReference and multilanguage contents / db_rewrite_sql() patch #22.

andypost’s picture

Status: Reviewed & tested by the community » Needs work
+++ nodereferrer.module	8 Feb 2011 15:13:58 -0000
@@ -136,7 +136,18 @@ function nodereferrer_field($op, &$node,
+      if (function_exists('i18n_selection_mode')) {

This pattern is used too often, glad to commit, but we need to optimize this into static caching

mvc’s picture

@andypost: i agree that it would be good for this to be optimized. but currently the code is simply not correct. personally, i feel that incorrect code is worse than suboptimal code. if this was a new feature, i would also suggest not applying the patch until it had been optimized, but here we're simply making it possible to use this module with i18n.

anyways, just my $0.02.

andypost’s picture

+++ nodereferrer.module	8 Feb 2011 15:13:58 -0000
@@ -490,7 +513,18 @@ function nodereferrer_nodeapi($node, $op
+        if (function_exists('i18n_selection_mode')) {
+          i18n_selection_mode('reset');
+        }        ¶

I still sure that implement a static cache for this is easy, see check_plain/6

Also please remove trailing whitespace

mvc’s picture

Version: 6.x-1.0-rc2 » 6.x-1.x-dev
Status: Needs work » Needs review
FileSize
3.87 KB

okay, here's that patch with static caching added and the whitespace fix.

andypost’s picture

Thank you!

Now let's wait for reviews from other users because currently I'm not using i18n for D6

+++ b/nodereferrer.moduleundefined
@@ -129,13 +129,28 @@ function nodereferrer_field_settings($op, $field) {
+  if (!isset($function_exists_i18n_selection_mode)) {
+    $function_exists_i18n_selection_mode = function_exists('i18n_selection_mode') ? TRUE : FALSE;
+  }

TRUE : FALSE is useless here because function_exists() returns boolean