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.
Problem/Motivation
#2494959: Add translation integration added support for translating referenced entities along with their 'parents'. This works well, except that it breaks the IEF widget when a new 'parent' entity in a non-default language is created.
Steps to reproduce:
- Install Drupal 8 with IEF.
- Make sure there are two content types, both translatable. Their languages must be configurable in their forms.
- Add an entity reference field to one of the content types, targeting the other type.
- Configure the ER field to use the Complex IEF widget.
- Add a node of the type with the ER field. Change the language to anything else but the default language, and add a new entity reference value.
- Confirm that the form does not appear. No errors are shown or logged.
Proposed resolution
Make TranslationHelper::isTranslating()
return FALSE
if the entity the form state is for is new.
Remaining tasks
None.
User interface changes
None.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#21 | translatable_field-2747781-21.patch | 924 bytes | vladimir_kriukov |
| |||
#20 | translatable_field-2747781-20.patch | 885 bytes | rudins |
#15 | inline_entity_form-2747781-15.patch | 2.29 KB | ckaotik |
#13 | inline_entity_form-2747781-13.patch | 2.38 KB | ckaotik |
#7 | inline_entity_form_2747781_6.patch | 2.36 KB | Xano |
|
Comments
Comment #2
XanoThis is a proof-of-concept patch.
Comment #3
XanoComment #5
XanoComment #6
XanoThis leverages the existing test to create the error condition. We know it works if the test's original workflow does not fail, as demonstrated by the test-only patch.
Comment #7
XanoAnd now, new and improved, with patch and interdiff.
Comment #9
paulmckibbenThanks for the patch. Unfortunately, here is what happens when I try it. (Using latest 8.x-1.x-dev version of inline_entity_form plus the patch in #7)
1. When I create a translation and change the source language to a non-default language, the inline entity reference fields appear to update to the values corresponding to the new language.
2. However, when I save the translation and then view it, the values in the inline entity reference fields are for the default language, not the language I selected.
Comment #10
johnwebdev CreditAttribution: johnwebdev commentedWe also have the same issue.
We have 2 languages enabled.
We have Inline Entity Forms installed.
We created two new content types where one has a object reference to the other. It uses IEF Complex.
We add a node in the primary language. (We don't fill any value in the IEF).
When we translate it's empty, no errors or logs.
If we update the original node with a value, the form is there, but we cannot add another entity to that translation. This is important, because we want the reference field to be translatable as well.
Comment #11
XanoBump. We just ran into this problem again elsewhere, and I realized the patch had not been approved/improved yet.
@paulmckibben @johndevman: Could you extend the patch with a test case that does what you did and exposes the problem? If not, can you provide more detailed, explicit, step-by-step instructions on how to reproduce your problem on a clean installation using the latest Drupal 8.3.x-dev, and the latest Inline Entity Form 8.x-1.x-dev?
Comment #12
johnwebdev CreditAttribution: johnwebdev commentedSteps to reproduce:
1. I've downloaded Drupal 8.3.x-dev and latest Inline Entity Form 8.x-1.x-dev.
2. I installed with Minimal profile
3. I enabled Languages modules and added language Swedish. Now I have two languages English (default) and Swedish.
4. I create content type Foo which has translation enabled.
5. I create content type Bar which has translation enabled. I add a "Foo reference" field which has translation enabled.
6. I set Foo reference field to IEF Complex, and add setting: "Allow users to add existing nodes." only.
7. I verify that each content type has translation enabled for all fields.
8. I add a "Foo" node (English) and translates it to Swedish as well.
9. I add a "Bar" node (English) without adding any reference.
10. I translate Bar node to Swedish and cannot see IEF form at all.
11. I apply patch "inline_entity_form_2747781_6.patch" and checks again. Clears cache. No difference.
12. If I change the Foo reference to use "Autocomplete" form display instead, it works as expected.
I read through the parent issue, it seems like this is intended behavior (that the entity reference is not translatable itself). If so this could probably be ignored / moved to another issue.
Comment #13
ckaotikI have tried to descern the various translation use cases in #2836102: Translation behavior is broken in some use cases. As far as I can tell, this issue is indeed because of the
isTranslating()
detection. It works nicely for non-translatable fields but causes issues when the ER field is translatable.As a workaround, I also check if the field is translatable, and if so don't apply this logic. However, this should still be solved generally for translatable fields, which is why I created the above mentioned issue.
Comment #15
ckaotikI'd better try with the correct patch file ...
Comment #17
johnwebdev CreditAttribution: johnwebdev commented@chaotik The patch seems to work fine from here. Shouldn't we use the issue #2822764 to keep on it though?
Comment #18
rockaholiciam CreditAttribution: rockaholiciam commentedThere are still a couple of things that need some work.
1. If I add a new parent node and change its language, although it now allows me to add referenced nodes (after applying patch in 16), but fails when you go and save the parent node. This happens when you have added a new referenced node instead of an existing one. Although it works with adding existing nodes but since interface language is different, the referenced nodes show up in interface language in the IEF (Complex), albeit they appear fine when viewing content.
2. Referenced entities although appear fine on node view for translated node, however in the IEF (complex), they appear to be referring to the entities source language.
3. If now a new reference is created in parents translation that doesnt exist in source language or hasnt yet been translated in source language, it appears fine in IEF complex edit form. If we now translate that referred entity and add it to source parent as well, it appears to be referring to the translated version while the translated version continues to refer to the correct version.
2 and 3 hint that somehow, the referenced entity created first is the one thats tracked within IEF (complex).
Comment #19
timodwhit CreditAttribution: timodwhit commentedI was not able to reproduce this on a clean install with the steps above. Are particular settings required to force this situation or is it possible that this was resolved in the releases after this issue was created?
Comment #20
rudins CreditAttribution: rudins at Wunder commentedLet's not mess with tests, as for now module suggests to not use this widget with translatable fields.
Comment #21
vladimir_kriukov CreditAttribution: vladimir_kriukov as a volunteer commentedDrupal 10 patch