Hi,
It seems it's impossible to create a content in another language as the current one, if we choose the current language as default configuration for Entity Translation.
How to reproduce the issue we currently have:
- enable Entity Translation, add some languages, choose "current language" as default language on node creation ;
- create a content while being in english language ;
- try to change the language to something else in the form ;
- save.
The content is displayed correctly, but the field is saved with "en" language, and editing the content is therefore broken since field values have disappeared.
I've track the behavior to the getFormLanguage()
function.
It seems removing some code does the trick, and I didn't see any negative effects, but I haven't tested every use case. From what I gather, this code is currently being refactored, so it's possible it will disappear anyway, but for now, it's the only way I could fix the bug.
I don't think it's major since there is a workaround (hiding the "Language" field and setting the language directly), but still, the functionality is broken ;-)
Comments
Comment #2
Simon Georges CreditAttribution: Simon Georges at Makina Corpus commentedHere is the patch we are currently using.
Comment #3
Alexander Fedorenko CreditAttribution: Alexander Fedorenko commentedHi Simon,
I think you're facing the same issue as I was facing couple days ago. I've tried to analyze the reason of why it is happening in this thread https://www.drupal.org/node/2870524#comment-12077074
Can you try proposed patch and check if it resolves your issue? Apparently there was some reason for changing the logic of getFormLanguage() method in beta6/dev version of module.
Comment #4
Simon Georges CreditAttribution: Simon Georges at Makina Corpus commentedSure, I'll test the patch today! Thanks for the feedback.
Comment #5
Simon Georges CreditAttribution: Simon Georges at Makina Corpus commentedAlexander,
I can confirm the patch in #2870524-28: Field copy fails with content translation for fields with entity translation enabled is fixing the issue as well. I couldn't apply the patch in #30 because I didn't use the -dev version, but since the code is the same, I think it's good as well ;-)
Let's close this issue in favor of yours.
Comment #6
stefanos.petrakis@gmail.comThe patch available at #2877074-3: Refactor the entity_translation_language() callback to make it bundle-specific should solve this issue as well, following a different approach.
Comment #7
stefanos.petrakis@gmail.comHello @Simon,
I am trying to reproduce your issue, to be sure we are not missing sth important.
I cannot reproduce it though on the latest 7.x-1.x-dev, without any patches applied.
Which is the exact tag/version that caused the problem?
Comment #8
Simon Georges CreditAttribution: Simon Georges at Makina Corpus commentedI've add it happen with the 1.0-beta6.
Comment #9
stefanos.petrakis@gmail.comHello @Simon,
I tried wtih ET-B6 and I still cannot reproduce it, just tried it on simplytest me:
7.54 + ET-B6; en + fr as languages, en is default; Article has Field Translation enabled, Article->Body is multilingual, Article->DefaultETLanguage is current language.
On creating a new node, I switch the language selector to fr, add some content to body and save.
The newly created node is in fr, the content in fr and editing seems to work as expected.
Any other clues about your set up?
Comment #10
Simon Georges CreditAttribution: Simon Georges at Makina Corpus commented@stefanos: When you use 2 languages, are you using URL language prefix and setting a "/en" prefix to english, or just keeping the basic empty prefix? I don't see any other different setting I'm using :-(
(and thanks for trying to reproduce it precisely)
Comment #11
stefanos.petrakis@gmail.comHey @Simon, thanks for the patience. I am using the default empty prefix for english, with both Interface and Content detection set to URL.
My "Add article" URL looks like this then:
http://localhost/node/add/article
I also tried replacing the empty prefix with the 'en' prefix and got such a URL:
http://localhost/en/node/add/article
But, I still managed to create the content in the language I selected in the "Language" dropdown, the current language was not enforced.
You can check the setup I used here => https://rcneb.ply.st/ (admin:admin)
A sample article, created with the current language being 'en' and setting the form's language to 'fr' is here => https://rcneb.ply.st/fr/node/1/devel, and it seems to be created as expected.
Comment #12
Simon Georges CreditAttribution: Simon Georges at Makina Corpus commentedI don't succeed in reproducing it on your test setup, so I suppose it's environment-related? I'm on PHP 7, with a MySQL 5.7.x. Could there be something there?
Comment #13
Simon Georges CreditAttribution: Simon Georges at Makina Corpus commentedOn a second note: after adding a few modules on my test setup yesterday, I didn't have it either... So I suppose there is a very peculiar setup that produces this kind of issue. If I manage to track it, I'll give feedback here. In the meantine, my production website is working thanks to the patch in the other issue, so don't lose too much time over it.
Comment #14
drasgardian CreditAttribution: drasgardian at Eighty Options commentedI am experiencing this issue with 7.x-1.0
My content type is configured as per the attached screenshot.
If I goto /fr/node/add/document and then select English from the language field, the fields get saved with the language of fr.
Debugging from a hook_node_validate I can see that the field values already have the wrong language at this point.
If I change the configuration so that the default language is 'Language neutral', then the problem does not occur, but the language value in the form is not pre-populated with the user's language, which isn't ideal.
Applying the change in #2 appears to fix the issue.
Comment #15
stefanos.petrakis@gmail.comHi @drasgardian, will set this back to "active" and try to have a look soon following your set-up. Thanks for the update
Comment #16
stefanos.petrakis@gmail.comHello @drasgardian:
I managed to reproduce the error you described.
Here is a first try at fixing this. Using the patch from #2 is not advised as it essentially rolls back meaningful and intended changes (see #2438615: New nodes are always created using LANGUAGE_NONE (only changed to the correct language during form submission)).
Please have a try a let me know if that solves your issue.
Comment #17
stefanos.petrakis@gmail.comI finally managed to write some tests that can successfully capture the problem described in #14.
There seems to be some interplay of the Locale's module
locale_field_entity_form_submit()
that callsentity_language()
passing it an instantiated entity object that is lacking the translation handler id (see that function's code for more info).So, first off: The test I wrote (entity_translation-content_not_in_current_language-2877103-17_tests.patch) can capture the problem that @drasgardian reported in #14 and should fail when run alone.
Secondly, the patch I provided in #16 should take care of solving the issue and is very similar to the patch provided in comment #34 here (I will give credit accordingly).
The updated patch (entity_translation-content_not_in_current_language-2877103-17.patch) contains the new test - which should now pass - as well as small changes of the patch from #16.
Finally, a note for the E.T. code enthusiasts: I had to modify the
EntityTranslationFactory::getHandlerId()
code slightly to make sure that no "translation handler hi-jacking" takes place, i.e. new entities with no translation handlers assigned to them getting linked to existing handlers. This was particularly painful while writing the test case for #14, since I couldn't reproduce the problem inside Simpletest, even though I could easily reproduce it on the browser. After log debugging I came to the conclusion that inside Simpletest, somehow the issue with Locale does not manifest itself due to "translation handler hi-jacking".Comment #18
stefanos.petrakis@gmail.comComment #20
stefanos.petrakis@gmail.com@drasgardian: Much appreciated if you can give some feedback regarding this, specifically after applying entity_translation-content_not_in_current_language-2877103-17.patch
Comment #21
stefanos.petrakis@gmail.comI would like to see this committed soon since the proposed changes take care of the Locale module's problematic logic (instantiating the current entity using a object derived from the
$form_state['values']
array) which is causing trouble to Entity Translation's language detection/definition logic.I would really appreciate @drasgardian's feedback since he guided me to reproducing the error in #14; the latest patch should allow the error to be resolved, can you confirm this @drasgardian?
I will otherwise review the patch on my own and try to push this into dev in the following days.
P.S.: Raising this to Major to get some attention
Comment #22
Andras_Szilagyi CreditAttribution: Andras_Szilagyi at Randstad Digital for European Commission and European Union Institutions, Agencies and Bodies commented#17 worked for me
The way I tested was to:
Result: in view content shows, in edit content shows, all good
without the patch its not the case.
I've tested also different values in admin/config/regional/entity_translation and also with workbench_moderation, all good.
Comment #23
stefanos.petrakis@gmail.comHi Andras,
Very happy you could test this.
I tried to do this manually again, just to be sure.
But, I cannot reproduce the problem any more:
Contrary to what I expected, the new node had correctly saved the value into the correct field's language sub-array (body[en]).
Can you check my steps and let me know if I missed sth? Or, otherwise, give me some more details of how to reproduce the breakage?
Thanks again!
Comment #24
Andras_Szilagyi CreditAttribution: Andras_Szilagyi at Randstad Digital for European Commission and European Union Institutions, Agencies and Bodies commentedHi Stefanos,
the trick is to create the page from /en/node/add/article and select German from the dropdown.
In our use case we have sites in many languages, the content creators would browse in english and create content for the language needed.
Let me know if this makes sense for you.
Comment #25
stefanos.petrakis@gmail.comThanks Andras,
Will have another try and set it back to RTBC accordingly!
Comment #26
stefanos.petrakis@gmail.comHi Andreas, Still cannot reproduce it, hear are the steps:
The new node had correctly saved the value into the correct field's language sub-array (body[de]).
Please check the steps I describe here to help me reproduce the error.
Comment #27
Andras_Szilagyi CreditAttribution: Andras_Szilagyi at Randstad Digital for European Commission and European Union Institutions, Agencies and Bodies commentedHi Styefanos,
with the config u mention, create the page from /en/node/add/article and select German from the dropdown.
after go back to edit, you will see body content missing.
Comment #28
stefanos.petrakis@gmail.comHi Andras, thanks for the update, still no luck, on this instance https://stm5dcd1c1acfa3d-o0818l03j9gprixwqmtfzyapdfiottad.tugboat.qa/en/... (simplytestme)
Here are the visuals, problem still not reproducible:
Comment #29
stefanos.petrakis@gmail.comComment #30
Delphine Lepers CreditAttribution: Delphine Lepers at European Commission and European Union Institutions, Agencies and Bodies for European Commission and European Union Institutions, Agencies and Bodies commented@stefanos & @andras I think i "resolved" this mistery :)
When i apply @stefanos' steps i can indeed not reproduce the issue.
However, I can reproduce it if i create a new content type.
STEPS [same as yours]
On a fresh D7.67 install, with ET 7.x-1.0
Two languages, English default (with 'en' as the URL prefix) and German with 'de' as URL prefix
Enabled ET for the Article content type, with default language set to "current language" and language locking enabled
Enabled field translation for the body field ofthe Article content type
Visited the /en/node/add/article URL, switched the language selector to "German", added some text to the body field and saved
The new node had correctly saved the value into the correct field's language sub-array (body[de]).
Then, i create a Forum content type, using ET with default language set to "current language" and language locking enabled, body field is enough.
Visited the /en/node/add/forum URL, switched the language selector to "German", added some text to the body field and saved
The new forum node has an empty body in edit mode...
This makes sense when you look at the patch comments :/
Here are some screenshots
Comment #31
Andras_Szilagyi CreditAttribution: Andras_Szilagyi at Randstad Digital for European Commission and European Union Institutions, Agencies and Bodies commentedI've made a screencast
Comment #32
Delphine Lepers CreditAttribution: Delphine Lepers at European Commission and European Union Institutions, Agencies and Bodies for European Commission and European Union Institutions, Agencies and Bodies commentedHmm I have found even easier repro steps !
STEPS
On a fresh D7.67 install, with ET 7.x-1.0
Two languages, English default (with 'en' as the URL prefix) and German with 'de' as URL prefix
Enabled ET for the Article content type, with default language set to "current language" and language locking enabled
Enabled field translation for the body field of the Article content type *and delete tags and image fields*
Visited the /en/node/add/article URL, switched the language selector to "German", added some text to the body field and saved
body is empty on edit mode !
Comment #33
stefanos.petrakis@gmail.comThank you both for the fantastic help, very, very much appreciated.
I found the reason for not being able to reproduce the problem.
Delphine Lepers had found that too in her last comment; there is a case of form caching that causes the error not to manifest itself on forms where there are ajax-enabled elements.
This is the code responsible for caching (from includes/ajax.inc).
Which means that node types with no ajax-enabled fields will exhibit the erroneous behaviour and others, like I encountered in my test, e.g. the Article node type, with its ajax-enabled image field will not demonstrate the problem.
I updated the tests and I actually managed to capture the error by activating the caching on the node add form.
Re-rolling the tests and patch, we are very close to an end here and this will definitely trigger a new release as it is quite a significant fix.
Comment #36
stefanos.petrakis@gmail.comGreat, bot said we are ok, I just committed this and assigned credits accordingly, including people that participated in the related issue #2870524: Field copy fails with content translation for fields with entity translation enabled.
Thanks again to Delphine Lepers and Andras_Szilagyi: Your help was really invaluable!