Steps to reproduce:
1. Create a new node in English
2. Create a translation in French and add FR or something else obvious to the title
3. Edit the node in English
- note that the title is now the one entered for french.
- Look in {field_revision_title_field} and note that the title is the new French one for both the en and fr values.
This is because when new translations are saved from the entity translation UI, $node->title gets set to whatever the translated version is going to be. title_active_language() return 'en' during title_entity_presave(), so the English field value gets overwritten with the translated title.
I've got a patch which fixes the issue for me, this appears to work fine with the UI but there's one edge case where it'll break.
If you load a node, change node->title, then also add a new translation, then it woudn't update the title - but that's only possible via the API rather and seems unlikely.
Uploading patch once I've got an issue nid.
| Comment | File | Size | Author |
|---|---|---|---|
| #85 | title-sync-1991988-85.patch | 1.06 KB | hadsie |
| #84 | title-1991988-form-test-case-different-interface-and-content-languages-84.patch | 24.15 KB | ceonizm |
| #82 | title-1991988-form-test-case-different-interface-and-content-languages.patch | 24.14 KB | ceonizm |
| #78 | interdiff_10-78.txt | 539 bytes | kkkkzk |
| #78 | title-sync-1991988-78.patch | 812 bytes | kkkkzk |
Comments
Comment #1
catchComment #3
catchCheck if ->hook is set.
Comment #5
kristiaanvandeneyndeDuplicate of #1269076: Translated title_field replaces node->title with translated value?
Comment #6
catchNo this is still a bug with the revisions table, I've been using latest title module from after that change was made.
Better patch this time - if a translation is being created, force the 'active language' to that, in my testing even when creating a translation in German or French the active language registered as 'en'.
Comment #7
plachThis hunk looks unrelated. Why is it there?
Comment #8
catchHmm not sure why that crept into the patch.
This was resulting in the node title overwriting the field value when translations were being added in some cases, which is not what we want. Updated patch only allows that if the active + entity language are the same.
Comment #10
jbrauer commentedIf you are on node/###/edit/langcode and save the node the English title is also being overwritten, not just on insert. This updated patch works on insert and update
Comment #11
catchLooks good, back to the bot.
Comment #13
owen barton commentedThis is working for me - not sure why the test is failing though (even with dev entity and ET).
Comment #14
pere orgaApparently working fine here (also using dev versions)
Comment #15
pere orga#10: title_1991988-10.patch queued for re-testing.
Comment #17
pere orgaI switched back to 7.x-1.0-alpha7, patch #10 was causing titles being saved in wrong languages
Comment #18
jbrown commentedPatch in #10 fixed it for me.
Comment #19
jbrown commentedThis bug means that the primary purpose of the module does not work.
Comment #20
plachWell, at very least we need those test failures to be fixed too :)
Comment #21
andyhawks commentedpatch in #10 works for me despite fails.
Comment #22
dexx086 commentedpatch #10 works for me too, can somebody please review the last patch and check why does it fail? Would be nice to commit this patch if it works as expected. It's a "must have" fix for multilingual sites I think.
Comment #23
robloachComment #24
plachSorry, until either tests or the actual fix are adjusted to make tests pass this is needs work.
Comment #25
plachAnd I don't think this is critical: I have never seen this problem, so it must be probably caused by the interaction with some other module. This would be critical if you could reproduce it with just a D7 core + Title and Entity Translation, which is not the case.
Comment #26
jbrown commentedStrange - I have to apply this patch every time I use the module or it doesn't work.
Comment #27
plachYes, that's weird. I spent the last 4 days working on the integration between Entity Translation and Workbench Moderation and I did a lot of testing with Title enabled, but I never saw this issue :(
Comment #28
kristiaanvandeneynde@plach (#25): Did you test with or without revisions? From the OP it looks like the issue only arises when used with revisions. (The steps to reproduce are right at the top of the issue :) )
Comment #29
plachI tested with revisions, but since I was fixing revision support for ET this may explain why I didn't see the problem. I suggest you to try the patches in this queue:
https://drupal.org/project/issues/search?issue_tags=ET-WM%20integration
and see whether the issue is fixed after applying one (or more than one) of them.
Comment #32
kristen polRe #28, I have confirmed the behavior in the summary without revisions enabled for the content type.
Comment #33
kristen polOk... more info:
With a *vanilla* D7 install and latest (dev) versions of Title and Entity Translation, then I do *not* see this problem without revisions or with revisions enabled. So, that means it's something about our more complex codebase that is causing this. I'll post with findings once I pinpoint the problem code.
Upshot: This combination *did* work with or without revisions:
Drupal 7.41
Title 7.x-1.0-alpha7+14-dev
ET 7.x-1.0-beta4+10-dev
Comment #34
kristen polThe behavior I'm seeing is erratic. It sometimes works fine and other times wipes out the source content title. I cannot reproduce this reliably.
So... marking this for more info since we need steps to reproduce that are reliable.
Comment #35
kristen polComment #36
djg_tram commentedAdding my +1. This is a very serious problem. I arrived here from a very different scenario by actually narrowing down the problem to the same
title_entity_presave().In my case, I have a complete node with all translations present and correct (it comes from another Drupal installation but this is not important in this case) and whennode_save()calls allhook_entity_presave()functions, including title's, the node title is broken. The original title gets replaced with whatever current language is set on the site.The workaround for me right now is to use a replacement
node_save()and to make sure this module is never called in this situation.Comment #37
megadesk3000 commentedHello
I was facing the same problems with the title sync. Since i used a load_node and node_save in a batch processing we lost a lot of data and had to restore from a db backup. So this is really a serious problem as stated abobe.
Steps to reproduce:
- Create a node in english (lets assume nid is 1). Title is "Node EN"
- Translate the node to a different language with entity translation. (lets assume "de"). Title is "Node DE"
Just for testing load and save that node in hook_preprocess_page for example
The important part is the language you are currently on. (for example: mysite.dev/en or mysite.dev/de) in combination with the source language of the entity (en in our case), cause title_entity_language will always return the source language of the entity, and this is the problem, like explained below:
If you are currently visting the page in english everything is working as expected. Cause the title module syncs the the english title to the legacy field on node_load and cause the source language of the node is also english, it syncs back correctly to the english "replacement" field on node_save.
The problem occurs, if you are visting the page in german. Then it syncs the german replacement field (Title DE) to $node->title on node_load() via title_field_sync_get() and on node_save it syncs $node->title (Title DE) back to the english replacement field, which is wrong for sure. Also it does not replace $node->title with the originally stored value (Title EN), so $node->title gets also overwritten by drupals normal node_save mechanism.
The patch stores the language we sync from in title_field_sync_get() and uses this language to sync back correctly in title_field_sync_set().
Comment #38
megadesk3000 commentedComment #39
renrhafI faced the same issue with my french title being replaced by german ones, when browsing site in FR and editing a node with source language DE. I think your patch is on the good way but it was not able to fix the bug for us.
I'm still digging... this is very complicated to debug, it may be something site specific for us.
Comment #40
jefuri commentedUpdate patch #37, we faced some issues when saving entities. The _sync_source_lang was incorrectly set by the $langcode instead of the $entity->language.
Comment #41
renrhafSubmitting an interdiff for more visibility.
Comment #42
renrhafComment #43
kristen polThanks for the patch. Some minor nitpicks:
Wrap close to 80 chars (e.g. "that" can move up one line).
german => German
source' => source
english => English
german => German
english => English
german => German
english => English
Comment #44
jefuri commentedApplied review comments from Kristen Pol. And changed the added fix for $entity->language. Some entities do not have this property. So I created a fallback to $langcode.
Comment #45
kristen polThanks for the changes. Sorry for the picky feedback and that I didn't notice all of these before. In several places, the comments aren't getting close to the 80 character limit. I've noticed a few here but probably best to go through all the new comments to adjust as needed. Thanks.
"we" can move up.
"to" can move up.
"be" can move up.
Several words can move up.
Comment #46
jaymz9mm commentedI've had this issue as well. Editing the source language afterwards to restore it doesn't overwrite the other language, but I'm only working with two languages currently so I haven't seen how it behaves with more than 2 translations.
EDIT: It also may be worth noting that the menu link title in Menu Settings of a page has the same thing happen.
Comment #47
adrien.felipe commentedPatch #44 did not work for me, while patch #37 does work. I'll be using this latter for now.
Comment #48
ericmulder1980 commentedI can confirm that patch #44 fixes the problem when running automated processes like feeds imports. The same patch however breaks the node edit form, changing the title in in a language that is not equal the entity->language will replace the title field that is equal to the entity->language.
My fix for now is using patch #37 and forcing users to always use the English interface while running feeds imports.
Comment #49
mkly commentedPatch #37 fixed the editing of the title changing the source language as well.
Comment #50
hgoto commented#2267251: Do not rely on "content language" in hook_entity_presave() seems to be related. It has a patch with tests now.
Comment #51
mrchristophy commentedJust dropping in to say that I'm also experiencing this issue, especially when doing batch node_load node_save processes. As someone else said, it seems erratic, and I can't find any patterns. I've applied the patch from #37 - will see how it goes.
Comment #52
joseph.olstadperson (link below) reports that patch 10 was working. Since head tests are fixed, lets re-roll patch 10, simple re-upload, didn't touch it. Just going by what was reported (link below)
#2844496-13: Translated field value is overwritten with legacy field value
Comment #53
joseph.olstadah, turns out I didn't have to re-upload patch 10, there's a retest link next to that old test. Looks like drupal.org fixed things so that still valid older patches don't need to be re-uploaded tests can be re-triggered..
Comment #55
joseph.olstadwaiting for results of tests triggered for #44 , #44 might be the lucky one.
Comment #56
joseph.olstadComment #57
joseph.olstadComment #58
joseph.olstadpatch 10 has less failures.
only 2 fails
patch 44 has 3 fails.
alternatively, there is also this:
#2844496: Translated field value is overwritten with legacy field value
haven't tested any of these myself though, was just triggering tests for fun.
Comment #59
furamag commented#10 works for me.
Comment #60
johnnieg commented#10 works. Not sure why it fails testing.
Comment #61
nchase commented#10 works for me.
Comment #62
jfcolomer commented#37 Works for me, thanks!
Comment #66
pifagorComment #67
joseph.olstadthis patch isn't outdated (patch 10), people are still using it.
see #2844496: Translated field value is overwritten with legacy field value
I also comment, this patch appears to improve test results, before patch 4 errors (on head)
after patching only 2 errors.
Comment #68
joseph.olstadpatch needs a reroll
also, see
#3061862: Broken tests since commit 8d4ee39 (19.July.2018)
Comment #69
pifagorComment #70
joseph.olstadrerolled patch 37
no change to the patch.
NOTE: I have NOT tested this.
Comment #72
joseph.olstadComment #73
dylf commented+1 for RTBC
Comment #74
stefanos.petrakisSorry, this should not RTBC-ed without some details on how this was verified and most importantly without green tests.
Comment #75
stefanos.petrakisQueued the re-testing manually, let's see them turn green first.
Comment #77
lexsoft commented+1 to get this fixed
Comment #78
kkkkzkComment #79
philyPatch #78 works for me using Drupal 7.78 with French and English languages (3 websites).
And it passes the tests, cheers!
Thanks.
Comment #80
stefanos.petrakisHi @PhilY (and every one else watching this)
Cannot reproduce with latest ET + Title + Revisions, following the OP description.
Could you summarize how to reproduce the problem.
This issue is dated and there are different reports in here on how to reproduce.
Then I could try to add some tests for this case.
Comment #81
joseph.olstadStephanos please action this in title and et projects
https://www.drupal.org/project/entity_translation/issues/3197042
Comment #82
ceonizm commentedHello,
As I've reproduced the problem with the latest update I took a bit of time to write a test that demonstrates the problem because my guess by reading the comment is there may be an understanding problem. I hope this test may clarify things.
Basically the problem occurs when using entity_translation and edit an entity with an interface language different of the content language for example with url like
The root cause is you rely on the $language_content variable in title_active_language which in that case doesn't give the expected value.
If you just use the basic links provided by entity_translation language switch you won't notice that case because interface and content language are the same.
Here's a patch that adds the test and the fix to the title_entity_presave method (I made a mix of previous working proposed solution like #78)
just added a dependency to field_ui module in TitleFieldReplacementTestCase.
All tests are green (at least on my computer :p)
Best regards.
Comment #83
stefanos.petrakisA ton of thanks @ceonizm, I will try to work on this as soon as possible.
Comment #84
ceonizm commentedHello,
Here is a small fix to my previous patch that makes tests pass on php 7.4 (at least on my computer).
Best wishes and happy new year ;)
Comment #85
hadsie commentedThe rerolled patch in #78 is missing one change from the patch in #10 which is causing the the translations to not work in some cases. I don't see any comments as to why that line of code was removed so I've rerolled #10 including the missing line.
Comment #86
stefanos.petrakis@hadsie:
You mean this change from #10 went missing, right?
The reroll from #85 needs a reroll :-)
Comment #87
anrikun commentedWhy @stephanos?