This code, in nodeblock_block(), has some unexpected behavior:
$translations = translation_node_get_translations($node->tnid);
if ($translations[$language->language]) {
$node = node_load($translations[$language->language]->nid);
}
elseif (!$node->nodeblock_translation_fallback) {
// if no translation was found, and not using the fallback option
// return nothing, so the block doesn't display.
return;
}
For example, when viewing a site in English, if a nodeblock has been created w/o the fallback option selected, then the block won't display in English (the default language). It seems that the intended behavior is to hide the block if a translation doesn't exist for non-default languages. Shouldn't the block always display on the default language?
If that is the intended behavior, perhaps some more detailed explanation is needed here to clarify:
If checked, the source translation node will be used when a translation for the current language does not exist. If unchecked, the block will not be displayed if a matching translation does not exist.
I'm happy to
Comments
Comment #1
tom_o_t commentedHi Jonathan,
I can't recreate this issue.
I created a node (nodeblock) in the site's default language, did not check the 'fallback' option, and assigned it to a region.
When viewing the site in the default language, the block displayed as expected.
When switching to another language, the block did not display (again, this is the expected behaviour).
Did you do anything different than this?
Could you test again?
If you still have this problem, could you provide more info to help debug please?
- what is your site's default language?
- confirm that you've placed the block in a valid region
- confirm that the block/node has content
- put some dsm() calls in the code to see what's returned by translation_node_get_translations()
- etc.
Cheers,
Thomas
Comment #2
jhedstromHey Thomas,
Here's how I reproduce it. I create a node block, either in English (site default) or Language neutral. The block is not translated, and I have not selected the fallback option. When the code gets to the code in the original post, $node->tnid is empty, because there is no translation. As such, the $translations variable comes back empty, so the first check $translations[$language->language] fails, because $translations is null. The second condition though, !$node->nodeblock_translation_fallback is true, and thus the block isn't returned.
If this is still not reproduceable, I'll dig in further to see if i18n block translation is doing something odd.
Thanks,
Jonathan
Comment #3
tom_o_t commentedThanks for the additional info Jonathan.
I was testing it on an existing site that has a bunch of other language-related modules, so perhaps one of them was causing $node->tnid to have a value.
When I next have some time I'll spin up a clean install and try to replicate.
Thomas
Comment #4
aschiwi commentedI can confirm this issue. After weeks of running a site with region_manager and nodeblock in one language, I added English as the second, non-default language of the site. When on your site's default language and creating a new nodeblock, it will not show up if you don't check the language fallback option, even if you choose the language for both the node and the block it creates. I didn't try with the non-default language.
Comment #5
tom_o_t commentedSee #707132: Translatable node: block is not displayed if there's only one language available and attached patch. Does this fix this problem? Marking this issue as a duplicate of the one with the patch.
Comment #6
Standart commentedI guess my patch from #707132: Translatable node: block is not displayed if there's only one language available addresses this in a way. Still, I think there's another conceptual issue here: The fallback is not a fallback to the default language but to the source language of the respective node, which is the one created first, no matter what's default on the site.
This behavior is by design and may have a valid use-case. A fallback to the default language - if present - would suit more users, however. At least it should be made very clear, what the fallback really does.