I'm confused that i can't find this issue in the queue and it seems as though it would be one of the primary purposes of this module.
- i have a node type with translatable fields
- i create 1 node and set as EN
- i am now able to translate the node
- i create a translation for FR and am able to set different values for the couple text fields which i have set as translatable
- when i go to the node in EN i see my english fields; when i switch to FR i see the french versions
Perfect!
now i add an entity reference field on another node type (actually to user profile) to point to this first node type and set display formatter to display the rendered entity.
when i show the user profile in EN i see the EN fields for my rendered entity.
when i switch to FR; i still get the EN version of the rendered entity.
am i missing something here? is this possibly a bug with entity reference more than ET?
| Comment | File | Size | Author |
|---|---|---|---|
| #117 | entityreference-n1674792-117.interdiff.txt | 1.04 KB | damienmckenna |
| #117 | entityreference-n1674792-117.patch | 36.91 KB | damienmckenna |
Comments
Comment #1
liquidcms commentedComment #2
liquidcms commentedComment #3
damien tournoud commentedNothing we can do until #1178500-14: hook_field_*() prepare/view have no access to the requested language is fixed.
Comment #4
liquidcms commentedthanks Damien for heads up... yea.. that thread (and the other one it links to) are getting pretty old now; would have to assume this won't get fixed... i'll look to hack something in... just wanted to be sure it wasn't some silly setting i was missing.
Comment #5
Sonya commentedWould you mind sharing your approach to "hacking something in" to tackle this problem? I've got exactly the same issue; I need to filter out referenced entities that are EN on pages that are FR.
Comment #6
liquidcms commented@sonya - as we have done a few times now we have bailed on the idea of translatable fields and gone back to translatable nodes as still too many issues with fields approach.
Comment #7
Cyclodex commentedHey.
I have the same issue and I am also looking to find a solution. It is a bit hard because it seems there are a lot of such issues, and anyway the different language settings are pretty hard ( a lot of different possibilities).
I am also testing some modules, which perhaps can help. I will post here any more information when I am able to produce a correct output. (so I am also checking for views/blocks etc. because the rendered entity was no success until now.)
Cheers
Comment #8
Cyclodex commentedEy peoples. It looks like I found a way with views creating me a block showing entity translated terms correctly.
But this is not specially related to entity reference, but perhaps a temporary or alternative solution.
For my use case I did this to show connected terms, but I think there are also possibilities for referenced "Nodes" or referenced entity's.
Just to show you what I got, including an export of the view. If you need more information or have problems let me know. I will perhaps investigate also other use cases for displaying entity translations.
Short note how to do it:
- Create a view to show terms
- add relationship "Entity translation: translations"
- add filter Entity translation: Language (=Current user's language) -> if you want to show the current language
With these filter options you can already create your content as you like.
For my use case I added also an contextual filter to relate to the current displayed node
And also some more magic happens with the Relationship "Content with term" which filters for only selected terms.
Some images and view export are attached.
This will already allow to show content where you want. If you use Display Suite you can really use this wherever you want.
Any feedback is welcome!
Comment #9
joelrosen commentedHere's a workaround that seems to be doing the trick for me for now:
In entityreference_field_formatter_view(), stick in a block of code that grabs the language from the global $language variable:
...
So as to avoid hacking entityreference, I stuck this version in my own module with my own definition in hook_field_formatter_info().
Comment #10
janlaureys commentedThat workaround seems to work for now. Thanks JoelRosen, but right I can only get it working hacking it in into the contrib module. Could you explain how you implemented it with the hook_field_formatter_info() ?
Comment #11
joelrosen commentedI just made duplicates of all the hook implementations that entity reference provides. So just copy entityreference's implementations of the following hooks:
hook_field_formatter_info()
hook_field_formatter_settings_form()
hook_field_formatter_settings_summary()
hook_field_formatter_prepare_view()
hook_field_formatter_view()
Change the names for your custom module and any other tweaks you need. Anyway I'm not actually sure if you even need to implement all these hooks.
Comment #12
damien tournoud commentedGuys, please help #1178500-14: hook_field_*() prepare/view have no access to the requested language get in. There is nothing obvious we can do until this is fixed.
Comment #13
damien tournoud commentedComment #14
dave reidJust ran into this with a project. When using entity translation with entity reference, you don't want to enable translation for your reference fields, which means all the field data gets saved with the LANGUAGE_NONE language. Calling field_view_field() on a node with this reference field with $language not provided (meaning to use the current language, let's say 'fr' for French) means that by the time we get to entityreference_field_formatter_view(), $langcode is actually LANGUAGE_NONE and so the referenced entity is not rendered using French.
Having a fix in entityreference would be nice because in the mean time we not only have to patch entityreference but also core. Patch attached in case anyone else finds this useful.
Comment #15
Anonymous (not verified) commentedI have added the above lines to entityreference.module
version = "7.x-1.0+0-dev" on line 1242 and it fixed the language issue.
Could this be committed to the module so we don't get this issue on module update.
Comment #16
damien tournoud commented#14 is basically a hack, but I guess it improves the situation in most use cases.
Let's make this behavior configurable (in the formatter settings), and get this in.
Comment #17
valderama commentedI added a formatter setting to Dave's patch.
Thanks everyone..
Comment #18
dave reidI wouldn't really be happy with having to enable this every time when it should be automatic if $langcode = LANGUAGE_NONE. Is there a way this can be configurable but enabled by default or more automatic?
Comment #19
Jason Dean commented#17 worked well for me (and saved the day!).
Comment #20
Anonymous (not verified) commentedThanks all!
#17 works for me, maybe commit it?
Comment #21
dave reidI still do not think that this should be disabled by default and committed as-is. An core fix has no momentum, and any multilingual site will have to go through and re-edit all their entity reference field configurations.
Comment #22
valderama commentedI changed the default value of the formatter setting to TRUE - according to Dave's comment in comment #18.
However as there probably is no real use case for NOT using the the content language for the rendered entity, I think Dave's original patch from comment #14 is also fine.
Comment #23
billyroebuck commentedThanks a lot for looking into this. After applying patch #22, checking the new setting, clearing the cache, this solved my issue!
Comment #24
badrange commentedThis patch fixed an issue for me where I have a node translated content type that references another one that was entity translated.
After applying the patch in #22 entityreference does indeed fetch the correct language version of the entity translated target.
Comment #25
interdruper commentedPatch #22 fixes the issue also for me.
IMHO the patch is RTBC
Comment #26
askibinski commentedPatch applies cleanly against latest dev and fixes a big issue with entity translation.
Comment #27
Leeteq commentedToo bad this did not get in before the security release that came out this morning. What's the perspective for the next stable release?
Comment #28
vacilando commentedDoes not work for me, unfortunately...
I have a content type with a multivalue field containing references to other nodes in the same content type. I took the current dev of the module, applied patch from #22, set the formatter to "Rendered entity" and pointed it to a view mode of the content type where only a linked title is enabled.
Cleared all caches.
Still, the multivalue entity reference field points to nodes in all sorts of languages, even though the current node is in EN. Using URL path language recognition, also for the default (English) language.
Comment #29
interdruper commented@Vacilando: I have a similar environment (using Entity Translation, not i18n) and the patch works fine. Make sure that you DO NOT have translation enabled for the Entityreference field itself; all the translatable fields from the referenced entities will be shown in the current user language.
Comment #30
interdruper commented#30: Re-rolled patch #22 against the current 7.x-1.1 release.
Comment #31
interdruper commentedComment #32
jbrown commentedPatch #30 works for us!
Comment #33
jbrown commentedComment #34
Anonymous (not verified) commentedPatch from #30 is working for me.
Comment #35
mxtPatch #30 works great for me also.
Can this be committed please?
Thank you very much
Comment #36
lstirk commentedConfirm patch #30 seems to be working well
Comment #37
ndf commented#30 is a nice patch.
Comment #38
honza pobořil commented#30 works for me (required clear cache)
Comment #39
noel.rivas commentedWorking great after applying #30.
Just one thing: if Use current content language is not checked in the display settings for the field, I get a PHP Notice complaining about use_content_language not being set, in line 1273 of entityreference.module.
In line 1273, defaulting to use current language gets rid of the notice, but I'm not sure if it's a good idea:
Otherwise, checking for the key would get rid of the notice:
Comment #40
giorgoskRecreated the patch as it was not applying on latest 7.x-1.x-dev
using the apply patch from netbeans IDE (maybe because of line numbers)
here is the new patch but exactly the same as #30
I also confirm that it works as advertised
please commit there is a lot of evidence above that it works as advertised
Comment #42
giorgoskOK maybe its not needed
but in my system it was not applying
Comment #43
pobster commentedI wish this would just get committed, I've been using variations of this exact patch for over a year now...
Pobster
Comment #44
ndf commented#42 re-rolled.
Comment #45
s_leu commentedAdded a condition that prevents the notices that occur until the formatter settings aren't re-saved
Comment #46
fietserwinI ran into this problem as well. My observations:
- #14/@Dave Reid is correctly explaining what is going on.
- For most fields this is the correct behavior, thus IMO no bug in core, but for entityreference this poses a problem of loosing the language in which to render the referred entity.
- So a solution should be in entityreference.
Should the solution be applied when LANGUAGE_NONE is passed in (@Dave Reid) or based on a setting (#16 Damien Tournaud)?
The only case I can think of, where the result could differ, is when having a double reference a -> b -> c, where b is not available in the language a is being sdisplayed in (the content language), but c is available in both the content language and the default/fallback language of b. What language do we want c to be displayed in? If we make it configurable we can choose, otherwise it will always be the language of b.
Thus making it configurable leaves the choice to the site builder. So I prefer the patch as it currently is (#45).
I reviewed and tested that patch. so the RTBC as set in #42 is now an RTBC for patch #45.
Note: workaround is setting the field to translatable, but that might loose sync between the different languages when changing the reference (not when initially setting the reference in the main language before translating the entity).
Comment #47
pianomansam commentedI have also applied patch #45 and seeing it resolve the issue.
Comment #48
adamgerthel commented#45 worked well for me as well
Comment #49
marcusx commentedUsing the patch #45 for a while now. No problems.
Comment #50
s_leu commentedWould be great if this could finally get committed. If you got reference fields within a feature this is messing up the feature states.
Comment #51
csedax90 commentedThere's a problem with this patch... it checks the right entity language but if I use entity translations without the language fallback it show the white entity instead. I think it should check if at least a field is in the current language, for example the Title Field...
Comment #52
pvhee commented#45 resolves the issue, but I agree with #50 that because it's not committed feature behavior changes, so I'm a little uneasy to apply this.
Comment #53
mxt#45 resolves the issue and works well since months in a pair of production sites.
Please commit this.
Thank you very much
Comment #54
milos.kroulik commentedThis also works for me.
Comment #55
liampower commentedThis doesn't work if your administration language is set to be one language, even with translated content. This is because to when you edit translated Nodes they don't default to the translated language, they stay in English using a standard URL, not one with the language code at the beginning. This is causing only English content to show up in the entityreference field.
Comment #56
kitikonti commented#45 resolves the issue for me.
Comment #57
Anonymous (not verified) commentedComment #58
Anonymous (not verified) commentedWe should help keep future developers sane and not override the $entity and $langcode variables. Here's an updated version of #45
Comment #60
Anonymous (not verified) commentedWhile trying to reproduce (without success) the issue reported by LiamPower at #55, I came across the settings for "Content language detection" and realized that if you have this issue with untranslated references it is not obvious that there is a fix for it in the "Field Display" settings.
1. I would suggest removing the settings altogether and respect the global content language settings or at least enable the setting by default. And maybe move it next to the "Field translation" settings in the field settings.
2. Has anyone tested how this patch affects a setup that does not use the field based translation exposed by entity_translation?
3. Can anyone tell me why this patch is using the global $language_content (couldn't find where it is set).
And depending on the answers for 2&3 there is this:
4. If this is only for entity_translation.module, then we should and probably use entity_translation_get_existing_language(). see: #2073231: Rename entity_translation_form_language() to entity_translation_get_existing_language() and for a patch on how to determine the entity language: #2364113: Support for Entity Translation
P.S. I'm going to do more tests on this with different setups.
Comment #61
johne commented#58 worked great in my case.
Comment #62
pakmanlhPatch in #58 works like a charm. Thanks!
Comment #63
pakmanlhComment #65
rodrigoaguileraI reviewed the code and looks ok.
Comment #66
rcodina#58 works for me too. I hope this gets committed soon!
Comment #67
axe312 commented#58 is also working for us in several projects :)
But we need tests.
Comment #68
axe312 commentedComment #69
tasc#58 works for me on 7.x-1.1
Comment #70
dragonfire353 commentedThis is a quick and dirty fix for people who need this linking to the current language version of the node NOW like me.
for non-dev version: 7.x-1.1
add the following after line 1267 in entityreference.module or if that isn't right for whatever reason under the "case 'entityreference_entity_view':" after "unset($entity->content);":
Again this was a quickly done fix because I don't have time so use at your own risk.
Comment #71
milos.kroulik commented#58 works also for latest 7.x-1.x-dev
Comment #72
ipa 🍺 commented#58 works for me to on 7.x-1.1
Comment #73
joekers#58 worked for me too.
Comment #74
mihai_brb commentedJust tested and #58 works like a charm.
Comment #75
shaxa commentedI have been struggling with this also for a while. Based on all patches and comments i have made my own patch which is working for all formatter types, because i use "Label" formatter a lot. The thing i did is that i load and replace the target entity with the translation entity. My patch is working only for nodes so be aware if you decide to use it.
Comment #76
kristiaanvandeneyndeThat's a nice approach for nodes, but we shouldn't display such a patch in the issue summary :)
Comment #77
ademarco commented#58 worked for me too.
Comment #78
ademarco commentedI've re-rolled #58 providing test coverage for the "Rendered entity" formatter being language-aware.
The test class enables a feature called "entityreference_entity_translation_test" which sets up what's required required to test the functionality at hand (e.g. adds a reference field to the article content type, sets the reference field formatter to "Rendered entity", and so on), then it creates 3 translated article nodes along with their references and tests that the formatter behaves correctly.
Comment #79
ademarco commentedComment #81
ademarco commentedRe-rolling after adding dependencies to
EntityReferenceEntityTranslationTestCase::getInfo().Comment #82
ademarco commentedComment #83
bircherThe test runs locally, and it was a re-roll of an RTBC patch. Lets see if the testbot tests only RTBC patches.
Comment #84
mohamedali commentedPatch #58 worked for me.
Comment #85
ademarco commentedPosting re-rolled #58 which includes tests.
Comment #86
ademarco commentedComment #87
valderama commentedWow, thanks for the tests!
Comment #88
ruichao commentedCan it do fallback when no translation of referenced entity available?
Comment #89
cathsens commentedPatch and tests tested : it works fine!
Thanks @ademarco
Comment #90
bircher+1 for RTBC
Comment #91
axe312 commentedWe are also using the patch from #58 and #85 in several projects. Works fine, please commit :)
Comment #92
joelpittetMe too: RTBC++
Comment #93
rossb89 commentedAnother confirmation - Patch #85 working correctly and solves the issue!
Comment #94
ademarco commentedAny chance we can get this committed? It seems we have receives quite a few positive RTBCs. Thanks!
Comment #95
axe312 commentedRemoving the "needs tests" tag since tests are now included.
I hope that helps to get the module maintainers aware of that issue.
Comment #96
grougy commentedConfirmation here too,
Patch #85 is solving my issue with taxonomies as entity reference fields.
Taxonomy fields are now correctly translated on the parent node (with entity translation)
Comment #97
csedax90 commentedI've found a problem with #85. It works correctly if a node hasn't a translation, but it fails when a node has a translation AND this translation is unpublished.
Someone else can confirm this problem?
Comment #98
jannis commentedApplied patch from #85 to a clean 7x.1x-dev and got a rejected hunk from the patch regarding tests:
Checking patch entityreference.info...
error: while searching for:
files[] = tests/entityreference.taxonomy.test
files[] = tests/entityreference.admin.test
files[] = tests/entityreference.feeds.test
error: patch failed: entityreference.info:22
error: entityreference.info: patch does not apply
Checking patch entityreference.module...
Hunk #2 succeeded at 1140 (offset 1 line).
Hunk #3 succeeded at 1172 (offset 1 line).
Hunk #4 succeeded at 1266 (offset 1 line).
Hunk #5 succeeded at 1279 (offset 1 line).
All the same - the hunks that worked fixed the problem for me! I was unable to reference entities unless they were all language neutral. Now I am able to reference as long as they are in the same language, translate etc.
I also checked my site for #97's issue with published vs. unpublished references causing any failures.
I think aside from the error with the patch, this has fixed the problem.
Comment #99
damienmckennaThis is a simple reroll.
Comment #100
rcodinaThe patch on #99 doesn't work for me. Let me explain:
Testing latest version of patch on #99 with simplytest.me button:
1) I create a new Entity Reference field named "Articles" on "Basic page" that references "Articles" with widget "select list". Unlimited values.
2) I enable "Content translation" module
3) I edit "Article" and "Basic page" content types to enable "Multilingual support" with option "Enabled, with translation" (both content types)
4) I enable Spanish language on admin/config/regional/language
5) I create a new Article named "Article EN" with language English selected
6) I create a new Article named "Article ES" with language Spanish selected
7) I create a new Basic page named "Basic page ES" with language Spanish selected. I see both "Article EN" and "Article ES" on "Articles" Entity Reference field => I consider this is correct because the node is not yet saved. However, something could be done with AJAX to filter options once language select changes.
8) Now I edit the recently created "Basic page ES" and I can still see "Article EN" => I consider this is wrong because "Basic page ES" has Spanish language selected.
Am I missing something?
Comment #101
valderama commented@rcodina
This issue here is not related to your observation - as far as I can see.
This issue deals with rendering of a referenced entity, which is translated in multiple languages (using Entity translation and not Content Translation). In that case the language of the parent entity is not passed on correctly to the rendered entity.
Please search the issue queue for an issue, which fits your problem description - or post a new issue if you did not find any other matching.
Thanks,
Walter
Comment #102
rcodina@valderama Ok, I've opened a new issue.
Comment #103
ademarco commentedSince the problem raised in #100 seems to be unrelated to this issue I'm marking this as RTBC again.
Comment #104
rcodina@ademarco What about the problem raised in #97?
Comment #105
gambryI'm not sure what #97 is about.
With entity_translation Publishing Options are for all Languages, so if a translation is unpublished the node is not accessible and entity_reference shouldn't display anything.
Tested on simplytest.me with Entity Translation 7.x-1.0-beta4 and Entity Reference 7.x-1.x.
Comment #106
nicrodgersJust to add that patch #99 applies cleanly and fixes the problem for me. +RTBC
Comment #107
rodrigoaguileraI also did some testing and reviewed the code. I consider this patch good to go into the main branch.
Comment #108
anybody+1 for RTBC + commit ASAP. Thank you all!
Comment #109
roderik de langen commented+1 RTBC, and indeed commit plz :D Thanx!
Comment #110
nikro commented+1 RTBC (#58 worked for me).
Yet another issue that lasts 4 years to be committed.
Comment #111
alibenski commented+1 RTBC
patch #99 works for me! Thank you!
Comment #112
rudins commentedRemoved ".info" part due "error: entityreference.info: patch does not apply"
Comment #115
damienmckennaRerolling my patch from #99.
Comment #117
damienmckennaThis should fix the tests - 7.50 added a new permission for fields that needed to be added to these tests.
Comment #118
ptsimard commentedI tested it with Simplytest.me on Drupal 7.50 and also on 2 other drupal sites of different version and I confirm that patch works perfectly for me.
Comment #119
damienmckennaThere's a "return;" in the last patch, I'm not sure where that came from (I haven't dug through each patch to find it) but I'm concerned it would have unintended consequences. Can someone please comment out that line and try the tests again?
Comment #121
minoroffense commentedRan into this bug today on a client site. Patch works, seems well tested. Committed to dev.
Comment #122
minoroffense commented@DamienMcKenna
With or without that return didn't seem to have an effect from what I could see. Continued to work. So I left it as is.Nm, different return value. I'll update the patch for the test.Comment #123
minoroffense commentedTracking that as a separate issue here: #2789493: Investigate stray "return;" in admin.test file
Comment #124
anybodyWould be cool to have a new stable release if this patch works for longer time... for i18n pages this is quite important.
Thank you all so much!
Comment #125
valderama commentedWow! Great to see this committed. I have added a patch four years ago in comment #17 :)
Happy!
Comment #127
HydroZ commentedI desparatly ran in this issue today and was glad to find a patch here. I tried to apply I without success.
Can someone help with the patching please?
That's what I tried:
1. I went to the version control page and downloaded the version 7.1-1.x via terminal:
2. Then I downloaded the patch from comment #115
3. Then I tried to apply the patches with
git apply -v entityreference-n1674792-117.patchand I get the error messages "...patch could not be applied".
By comparing the lines and replacements between patch and the downloaded reposititoy I see many mismatches, therefore I assume, that I did not get the right version in the first step... :(
Where do I get the version on which patches are based on? Thank you in advance for your help.
Comment #128
ptsimard commented@HydroZ The patch does not apply because it has already been committed and is part of 1.2 release.
What you are doing is getting the latest dev (which includes 11 more commits after that patch was committed, basically 1.2 + 10 commits).
So you have 2 choices:
Comment #129
HydroZ commented@ptsimard Thanks a lot for your answere. I think now I understood the whole procedure of patches and versions a bit better.
Are you really sure that the patch has fixed the error?
My current situation:
Exactly the same as #1 => I am working with entity field translation. Some fields are set to be translatable. To make the title translatable the "title field" module is enabled.
Content Type B has an entity reference field (select field with entity titles) but it shows only entities with translated titles (field title_field). The entities language itself does not matter.
A entity with the following field value would be available in the entity reference field:
So what can I do to make the et reference field show all contents (with translated titles and untranslated titles)??
Or is the Issue still not fixed?