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.
Comment | File | Size | Author |
---|---|---|---|
#7 | i18n_selection_mode-1054982-7.patch | 3.87 KB | mvc |
#1 | nodereferrer-1054982.patch | 2.84 KB | pbuyle |
Comments
Comment #1
pbuyle CreditAttribution: pbuyle commentedThe attached patch should set the i18n selection mode to a sensible value. A better approach may be to pass the whole
$node
object tonodereferrer_referrers()
(since we always have it) and set the i18n selection mode from there.Comment #2
pbuyle CreditAttribution: pbuyle commentedComment #3
mvcworks perfectly for me. i'm using it in combination with #671406: NodeReference and multilanguage contents / db_rewrite_sql() patch #22.
Comment #4
andypostThis pattern is used too often, glad to commit, but we need to optimize this into static caching
Comment #5
mvc@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.
Comment #6
andypostI still sure that implement a static cache for this is easy, see check_plain/6
Also please remove trailing whitespace
Comment #7
mvcokay, here's that patch with static caching added and the whitespace fix.
Comment #8
andypostThank you!
Now let's wait for reviews from other users because currently I'm not using i18n for D6
TRUE : FALSE is useless here because function_exists() returns boolean