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.

Comments

catch’s picture

Status: Active » Needs review
StatusFileSize
new745 bytes

Status: Needs review » Needs work

The last submitted patch, 1991988_title.patch, failed testing.

catch’s picture

Status: Needs work » Needs review
StatusFileSize
new822 bytes

Check if ->hook is set.

Status: Needs review » Needs work

The last submitted patch, 1991988_title.patch, failed testing.

kristiaanvandeneynde’s picture

Status: Needs work » Closed (duplicate)
catch’s picture

Status: Closed (duplicate) » Needs review
StatusFileSize
new1.26 KB

No 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'.

plach’s picture

+++ b/title.module
@@ -278,9 +288,7 @@ function title_entity_prepare_view($entities, $type, $langcode) {
+  $instance = field_info_instance($entity_type, $info['field']['field_name'], $bundle);

This hunk looks unrelated. Why is it there?

catch’s picture

StatusFileSize
new1.04 KB

Hmm 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.

Status: Needs review » Needs work

The last submitted patch, title_1991988-8.patch, failed testing.

jbrauer’s picture

StatusFileSize
new1.06 KB

If 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

catch’s picture

Status: Needs work » Needs review

Looks good, back to the bot.

Status: Needs review » Needs work

The last submitted patch, title_1991988-10.patch, failed testing.

owen barton’s picture

This is working for me - not sure why the test is failing though (even with dev entity and ET).

pere orga’s picture

Apparently working fine here (also using dev versions)

pere orga’s picture

Status: Needs work » Needs review

#10: title_1991988-10.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, title_1991988-10.patch, failed testing.

pere orga’s picture

I switched back to 7.x-1.0-alpha7, patch #10 was causing titles being saved in wrong languages

jbrown’s picture

Patch in #10 fixed it for me.

jbrown’s picture

Priority: Major » Critical
Issue summary: View changes

This bug means that the primary purpose of the module does not work.

plach’s picture

Well, at very least we need those test failures to be fixed too :)

andyhawks’s picture

patch in #10 works for me despite fails.

dexx086’s picture

patch #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.

robloach’s picture

Status: Needs work » Needs review
plach’s picture

Status: Needs review » Needs work

Sorry, until either tests or the actual fix are adjusted to make tests pass this is needs work.

plach’s picture

Priority: Critical » Major

And 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.

jbrown’s picture

Strange - I have to apply this patch every time I use the module or it doesn't work.

plach’s picture

Yes, 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 :(

kristiaanvandeneynde’s picture

@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 :) )

plach’s picture

I 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.

Status: Needs work » Needs review

Sergii queued 10: title_1991988-10.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 10: title_1991988-10.patch, failed testing.

kristen pol’s picture

Re #28, I have confirmed the behavior in the summary without revisions enabled for the content type.

kristen pol’s picture

Ok... 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

kristen pol’s picture

Status: Needs work » Postponed (maintainer needs more info)

The 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.

kristen pol’s picture

Title: Adding a new translation overwrites the English field value » Adding a new translation overwrites the English/source field value
djg_tram’s picture

Adding 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 when node_save() calls all hook_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.

megadesk3000’s picture

StatusFileSize
new3.36 KB

Hello

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

  function mymodule_preprocess_page(&variables) {
    $node = node_load(1);
    node_save($node);
  }

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().

megadesk3000’s picture

Status: Postponed (maintainer needs more info) » Needs review
renrhaf’s picture

I 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.

jefuri’s picture

StatusFileSize
new3.37 KB

Update patch #37, we faced some issues when saving entities. The _sync_source_lang was incorrectly set by the $langcode instead of the $entity->language.

renrhaf’s picture

StatusFileSize
new634 bytes
new634 bytes

Submitting an interdiff for more visibility.

renrhaf’s picture

kristen pol’s picture

Thanks for the patch. Some minor nitpicks:

  1. +++ b/title.core.inc
    @@ -134,7 +134,18 @@ function title_field_text_sync_get($entity_type, $entity, $legacy_field, $info,
    +  // with that one. Also it is important that the langcode is the same,
    +  // that we synced on load.
    

    Wrap close to 80 chars (e.g. "that" can move up one line).

  2. +++ b/title.module
    @@ -512,6 +514,26 @@ function title_field_sync_set($entity_type, $entity, $legacy_field, $info, $lang
    +    // If german, for example, is the active language and we load a node, which
    

    german => German

  3. +++ b/title.module
    @@ -512,6 +514,26 @@ function title_field_sync_set($entity_type, $entity, $legacy_field, $info, $lang
    +    // source' language is english, the english $node->title (Title EN) will
    

    source' => source
    english => English

  4. +++ b/title.module
    @@ -512,6 +514,26 @@ function title_field_sync_set($entity_type, $entity, $legacy_field, $info, $lang
    +    // be replaced with the german title field (Title DE) on node_load through
    

    german => German

  5. +++ b/title.module
    @@ -512,6 +514,26 @@ function title_field_sync_set($entity_type, $entity, $legacy_field, $info, $lang
    +    // Since $langcode is now the source language of the node (en), the english
    

    english => English

  6. +++ b/title.module
    @@ -512,6 +514,26 @@ function title_field_sync_set($entity_type, $entity, $legacy_field, $info, $lang
    +    // $node->title would now be replaced with the german title.
    

    german => German

  7. +++ b/title.module
    @@ -512,6 +514,26 @@ function title_field_sync_set($entity_type, $entity, $legacy_field, $info, $lang
    +    // which will sync to the legacy replacement field in english. So now the
    +    // english title would be lost both in the node table and also in
    

    english => English

jefuri’s picture

Applied 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.

kristen pol’s picture

Thanks 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.

  1. +++ b/title.core.inc
    @@ -134,7 +134,18 @@ function title_field_text_sync_get($entity_type, $entity, $legacy_field, $info,
    +  // with that one. Also it is important that the langcode is the same, that
    +  // we synced on load.
    

    "we" can move up.

  2. +++ b/title.module
    @@ -512,6 +514,26 @@ function title_field_sync_set($entity_type, $entity, $legacy_field, $info, $lang
    +    // If we saved the synced language in title_field_sync_get, we only want
    +    // to sync back to that language. Not always the entity source language,
    

    "to" can move up.

  3. +++ b/title.module
    @@ -512,6 +514,26 @@ function title_field_sync_set($entity_type, $entity, $legacy_field, $info, $lang
    +    // source language is English, the English $node->title (Title EN) will
    +    // be replaced with the German title field (Title DE) on node_load through
    

    "be" can move up.

  4. +++ b/title.module
    @@ -512,6 +514,26 @@ function title_field_sync_set($entity_type, $entity, $legacy_field, $info, $lang
    +    // This would happen also in title_field_text_sync_set(),
    +    // which will sync to the legacy replacement field in English. So now the
    +    // English title would be lost both in the node table and also in
    

    Several words can move up.

jaymz9mm’s picture

I'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.

adrien.felipe’s picture

Patch #44 did not work for me, while patch #37 does work. I'll be using this latter for now.

ericmulder1980’s picture

I 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.

mkly’s picture

Patch #37 fixed the editing of the title changing the source language as well.

hgoto’s picture

mrchristophy’s picture

Just 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.

joseph.olstad’s picture

StatusFileSize
new1.06 KB

person (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

joseph.olstad’s picture

ah, 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..

Status: Needs review » Needs work

The last submitted patch, 52: title_1991988-10.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

joseph.olstad’s picture

waiting for results of tests triggered for #44 , #44 might be the lucky one.

joseph.olstad’s picture

joseph.olstad’s picture

Status: Needs work » Needs review
joseph.olstad’s picture

patch 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.

furamag’s picture

#10 works for me.

johnnieg’s picture

#10 works. Not sure why it fails testing.

nchase’s picture

#10 works for me.

jfcolomer’s picture

#37 Works for me, thanks!

The last submitted patch, 10: title_1991988-10.patch, failed testing. View results

The last submitted patch, 10: title_1991988-10.patch, failed testing. View results

The last submitted patch, 10: title_1991988-10.patch, failed testing. View results

pifagor’s picture

Status: Needs review » Closed (outdated)
joseph.olstad’s picture

Status: Closed (outdated) » Needs review

this 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.

joseph.olstad’s picture

pifagor’s picture

Status: Needs review » Needs work
joseph.olstad’s picture

Status: Needs work » Needs review
StatusFileSize
new3.36 KB

rerolled patch 37

no change to the patch.

NOTE: I have NOT tested this.

Status: Needs review » Needs work

The last submitted patch, 70: title-sync-overwrite-fix-1991988-37_rerolled.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

joseph.olstad’s picture

Status: Needs work » Needs review
dylf’s picture

Status: Needs review » Reviewed & tested by the community

+1 for RTBC

stefanos.petrakis’s picture

Status: Reviewed & tested by the community » Needs review

Sorry, this should not RTBC-ed without some details on how this was verified and most importantly without green tests.

stefanos.petrakis’s picture

Queued the re-testing manually, let's see them turn green first.

Status: Needs review » Needs work

The last submitted patch, 70: title-sync-overwrite-fix-1991988-37_rerolled.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

lexsoft’s picture

+1 to get this fixed

kkkkzk’s picture

Status: Needs work » Needs review
StatusFileSize
new812 bytes
new539 bytes
phily’s picture

Status: Needs review » Reviewed & tested by the community

Patch #78 works for me using Drupal 7.78 with French and English languages (3 websites).
And it passes the tests, cheers!
Thanks.

stefanos.petrakis’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)

Hi @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.

joseph.olstad’s picture

Stephanos please action this in title and et projects

https://www.drupal.org/project/entity_translation/issues/3197042

ceonizm’s picture

Hello,
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

en/node/1234/edit/fr

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.

stefanos.petrakis’s picture

Status: Postponed (maintainer needs more info) » Needs review

A ton of thanks @ceonizm, I will try to work on this as soon as possible.

ceonizm’s picture

Hello,
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 ;)

hadsie’s picture

StatusFileSize
new1.06 KB

The 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.

stefanos.petrakis’s picture

Status: Needs review » Needs work

@hadsie:

You mean this change from #10 went missing, right?

   // Perform reverse synchronization to retain any change in the legacy field
   // values. We must avoid doing this twice as we might overwrite the already
   // synchronized values, if we are updating an existing entity.
-  if ($langcode) {
+  if ($langcode == $entity_langcode) {

The reroll from #85 needs a reroll :-)

anrikun’s picture

Status: Needs work » Needs review

The reroll from #85 needs a reroll :-)

Why @stephanos?

Status: Needs review » Needs work

The last submitted patch, 85: title-sync-1991988-85.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.