Hello!
Let's mark some node type as translatable with Entity translation, and then replace heritage node title with Title title_field. Then we'll create node, say, in French language with title 'TitleFr'. After that we'll translate this node in English, title for this translation will be 'TitleEn'. Node and it's translation will be rendered OK, with 'TitleFr' for French version, and with 'TitleEn' for English. But we'll see a problem at the database:
[vid] => 212
[uid] => 1
[title] => TestEn
[log] =>
[status] => 1
[comment] => 2
[promote] => 1
[sticky] => 0
[nid] => 157
[type] => article
[language] => fr
[created] => 1315126855
[changed] => 1315126855
[tnid] => 0
[translate] => 0
[revision_timestamp] => 1315126855
[revision_uid] => 1
[title_field] => Array
(
[en] => Array
(
[0] => Array
(
[value] => TestEn
[format] =>
[safe_value] => TestEn
)
)
[fr] => Array
(
[0] => Array
(
[value] => TestFr
[format] =>
[safe_value] => TestFr
)
)
)
As you can see, [title] => TestEn, though it should be TestFr. [language] => fr (i.e. correct).
Drupal 7.8, Entity translation -dev from 2011-Jun-20, Title -dev from 2011-Aug-21.
Comments
Comment #1
plachCan you reproduce this on a clean Title + Entity translation install with no additional module?
Comment #2
renat CreditAttribution: renat commentedYea, it is reproducible on clean D7.8 with Title, Entity Translation and Entity API 7.x-1.0-beta10. But there is one important notice - your node should be in language other than site's default, because title is overwritten with translation in default language, thus if node itself is in this language, there will be no problems. I think it is the reason this bug wasn't noted yet - most people publish content in the site's default language, and then translate it.
Comment #3
das-peter CreditAttribution: das-peter commentedJust thought about that. The only idea I've got is something like this:
Comment #4
mgladding CreditAttribution: mgladding commentedJust curious if there was any resolution...
Comment #5
plachPlease try the latest dev of Title and ET.
Comment #6
renat CreditAttribution: renat commentedUnfortunately, the problem is still there with dev version of Title (2012-Jun-13) and Entity translation 7.x-1.0-alpha2.
Comment #7
njmahesh CreditAttribution: njmahesh commentedI am having the same probe. Is this resolved? any patches?
Comment #8
yareckon CreditAttribution: yareckon commentedJust to note that with drupal 7.15 or newer, this seems to also be a problem with nodes that ARE in the site's default language. I have a site running 7.15 with six languages. A Node created in english and then translated into another language will have no problems until someone EDITS one of the translations. Then the title of the english node will be overwritten with the translated title. Editing the english title atain and saving is the workaround.
Comment #9
das-peter CreditAttribution: das-peter commentedCurrently the title module only handles this use case if it's used with an entity form.
I tried to tackle this in a generic way:
The new approach deals with this issue also in the case the term is stored programmatically e.g. by a migration.
I've tested the code extensively on our installations and I've extended the tests as well.
However, this desperately needs a review since the whole thing became more complex than I expected from a first look at the issue.
The only downside I see atm. is, that if you want to store the term programmatically, you've to set the form language using the entity translation handler.
Example:
Comment #10
Dave ReidI think I'm running into this as well. We have a migration that runs and updates existing nodes. In the migration I'm attempting to update the title_field values for both English and Chinese, but after title_entity_presave() runs the title_field value that I specifically set gets reset to whatever is in $node->title which is completely unexpected. Is this bug what this issue would cover?
Comment #11
plachYes, it seems we are currently addressing field language in the proper way only in
title_field_attach_form()
, whereas we would need to do the same (only) in the save phase.Comment #12
williamsowen CreditAttribution: williamsowen commentedI'm having the same problem. I have a node - original language EN, translated to FR. When a rule fires updating the entity for the FR version, it overwrites the title of the EN version. However, if the same rule fires on the EN version, FR doesn't get overwritten.. Tried the patch in #9 - didn't seem to work.
Comment #13
renat CreditAttribution: renat commentedRevert version to 7.x-1.x-dev, because not only 7.x-1.0-alpha4 is affected.
Comment #15
axe312 CreditAttribution: axe312 commentedI discovered this bug on 7.x-1.0-alpha4 in combination with panelizer:
* You need a panelized nodetype.
* You need 2 languages.
* Set your interface/page language to the non-default language.
When you edit the panelized node (no matter if you are using ipe or the panelizer tab), the title in the default node-version will be set to the value of the translation.
After updating to 7.x-1.x-dev I am still able to reproduce the bug.
Unfortunately I was not able to apply the patch from #9 to the newest dev! Can someone please reroll it agains the current dev-version?
(Set to major because this bug can destroy the whole integrity of the website)
Comment #16
my-family CreditAttribution: my-family commentedMaybe related (7.x-1.0-beta2) version: if I perform a bulk operation via Views Bulk Operations module via translated UI, the original title_field changes is populated by the translated value.
Comment #17
danielnolde CreditAttribution: danielnolde commentedThe attached simplistic patch title-sync-original-values-back-to-property-1269076-17.patch (created against alpha5!) seems so solve the problem at least when occuring with panelizer as described by axe312 in #15. Can anybody see whether/what side effects may be introduced?
Comment #18
danielnolde CreditAttribution: danielnolde commentedComment #19
plachI finally found some time to work on this. I think that attached patch is quite solid and should fix this issue without breaking too much stuff out there. The basic idea is that when saving an entity we should sync back the values from the legacy field to the replacing fields, but only when the active language, i.e. the language originally used to load the values into the legacy fields, matches the entity language. Otherwise we should perform the opposite process and restore the original values into the legacy fields.
The patch also introduces the concept of active language, which previously was hardcoded to the current content language. Now this is just a default that can be changed in any moment. The new test shows how the active language can be used in combination with
entity_load()
in programmatic workflows. Basically it's just matter of adding a line like the following to switch the language of the values synced into the legacy fields:Tests pass locally.
Comment #20
plachFixed a couple of typos.
Comment #21
plachHm
Comment #22
plachOther typos :(
Comment #23
das-peter CreditAttribution: das-peter commentedI gave this a visual review. Looks really nice!
I guess the essential stuff was to deal with
title_entity_presave()
,title_field_attach_presave()
and especiallytitle_field_attach_update()
to maintain the consistency.And it's awesome that we've a test case of the programmatic translation workflow now.
The only "concern" I've is that the title module has a weight of 100 - which likely makes the hook
title_field_attach_update()
the one that's triggered last.So there's an "inconsistency" for modules that implement
hook_field_attach_update()
too and are triggered before the title module. And according to the comment intitle_update_7001()
we can't use a lower weight.However, I think this is a reasonable risk we can take.
Summary: RTBC
Comment #24
plachThanks for the review, peter!
To answer your concern, Title implements
hook_module_implements_alter
and actually sets things up so that every hook besides a few ones is actually executed first, incudingtitle_field_attach_update()
. See:http://drupalcode.org/project/title.git/blob/refs/heads/7.x-1.x:/title.m...
That said, before committing this I'd like to have confirmation from people here (ideally all) that the patch fixes their issues.
Comment #25
plachWrong assert message
Typo
Should be "Current active language"
Comment #26
plachI realized we were missing
field_attach_presave
inhook_module_implements_alter
...Comment #27
plachAfter some more extensive testing I realized the former approach was not correct as it didn't cover the case of legacy field translations being manipulated on presave. Moreover I found that
title_tokens_alter()
was callingtitle_field_sync_get()
and thus it was altering the values of the legacy fields potentially during a presave hook execution. I fixed this to just retireve the needed values.Tests are green here.
Comment #28
DamienMcKennaNone of the tests are being ran by the testbot?
Comment #29
plachWe have issues with the testbots, it seems tests are not recognized: #1900282: Tests fail with "Failed to run tests: run-tests.sh reported no tests were found".
Comment #30
renat CreditAttribution: renat commentedIn my case node titles are still overriding with translated [to default language] ones. Should I provide additional information, or there are still plans to update patch from #27 significantly?
Comment #31
plachNope, #27 works perfectly for me.
Do you confirm the exact steps to reproduce your issue in the OP? Just the modules cited there?
Comment #32
elioshpatch #27 seems to work here.
Title: 7.x-1.0-alpha5
Entity Translation: 7.x-1.0-beta2
Drupal: 7.20
Comment #33
renat CreditAttribution: renat commentedGet it - I use Drush to display node data:
drush php-eval "print print_r(node_load(NID), 0)"
It still shows us the very same problem (Drupal 7.21, latest -devs of Title and Entity Translation, nothing more):
[title] => EnglishTitle
[language] => ru
[title_original] => RussianTitle
But in Node table at database everything is fine:
+-----+------+---------+----------+--------------+-----+--------+------------+------------+---------+---------+--------+------+-----------+
| nid | vid | type | language | title | uid | status | created | changed | comment | promote | sticky | tnid | translate |
+-----+------+---------+----------+--------------+-----+--------+------------+------------+---------+---------+--------+------+-----------+
| 1 | 1 | article | ru | RussianTitle | 1 | 1 | 1362744698 | 1362744752 | 2 | 1 | 0 | 0 | 0 |
| 2 | 2 | article | ru | RussianTitle | 1 | 1 | 1362744968 | 1362744992 | 2 | 1 | 0 | 0 | 0 |
| 3 | 3 | article | ru | RussianTitle | 1 | 1 | 1362745615 | 1362745641 | 2 | 1 | 0 | 0 | 0 |
+-----+------+---------+----------+--------------+-----+--------+------------+------------+---------+---------+--------+------+-----------+
So we should find out, is it Title problem now?
You can reproduce it just as in OP, e.g. make node type translatable [with ET], replace heritage Title with Title field, create node in language other than your site's default, and than translate it to your site's default language.
Comment #34
elioshFound a very annoying bug, but can't track down where/why.
To replicate:
Now, apply the patch, and step number 5 will give you a fatal error.
Comment #35
plachThe attached patch fixes the issue reported in #34, thanks.
Tests still green.
@renat:
I carefully followed the steps you described (btw, I almost always do my manual tests with nodes created in a non-default language) and I cannot find any problem. I think the behavior you are describing in #33 is the desired one: Title should store the original value in the legacy field storage, for instance in
{node.title}
, and the translations only in the field storage. When loading an entity the translation corresponding to the active language (by default the current content language) is written in the legacy field so that code accessing for instance$node->title
can find the translated value.The goal of this patch is ensuring that the original value is always stored in the legacy storage and that any modification performed to the legacy field is propagated to the corresponding field translation when saving the entity.
Comment #36
renat CreditAttribution: renat commentedPlach, yes, Title writes everything in DB just fine now. But Drush still shows us translated title rather than canonical in [title], and [language] is canonical there (i.e. doesn't match). It doesn't hurt me in any way (and never did), but I'm afraid it is possible that other contributed modules can get wrong title - language pairs as well. Would like to be wrong, of course.
Comment #37
plachThe reason probably is that drush uses the default language as current (-> active) language and thus you will always find the value of the corresponding translation in the legacy field. I think the current patch should be able to deal with that just fine.
Comment #38
plachI will create a last alpha in a few days and then I'll commit #35 if I receive no complaints before.
Comment #39
plachLast chance to review: I'm going to commit #35 this afternoon.
Comment #40
plachCommitted and pushed #35.
Tentatively marking fixed.
Comment #41
plachComment #42.0
(not verified) CreditAttribution: commentedIssue further explanation
Comment #43
yaelsho CreditAttribution: yaelsho commentedHello,
Did the patch resolve this issue?
I still have this issue. I had alpha7 installed. And upgraded to the last dev, but still the title is being changed post saving a translation.
I'm using the title token to set a node alias and would like to have the original language alias for all languages.
e.g.: example.com/[node:title] and example.com/es/[node:title]
Currently when adding translation the token [node:title] being changed, I thought only [node:title_field] should change.
Thanks, Yael
Comment #45
liquidcms CreditAttribution: liquidcms commentedhate opening this when:
1. it is closed
2. problem doesnt seem to exist on a vanilla site
but... ughh.,. i have exact same issue as reported here; sadly lots of other modules. i have disabled all the custom coded ones and most of the ones related to translation; but still problem persists.
- site was originally set up for node translation
- switched over to ET and enabled Title module
- edit english (default) version of node and set Title
- edit danish and set title
English title has now synced with the Danish title. I can set EN title back but any time i edit any other language; the EN title gets replaced.
should have been a 10 min task switching this over to ET.. been at this for hours now.. ughhh!!
any hints as to where i could but a breakpoint to see what is changing the title of the wrong field.
Comment #46
liquidcms CreditAttribution: liquidcms commentedstarted with a backup of site db from this morning and did a less aggressive approach to switching over to ET. simply enabled ET, Title and disabled i18n Sync. and started again, my original node i was testing with seems to be corrupted now; but i created a new node and it seems to be translating fine.
there is some odd issue where the first time i create a new node and pick English; it still gets saved as neutral; then i edit again and set to english again and this time it works.
pretty sure still issues with ET/Title; but possibly cleaner on fresh installs than trying to switcho ver from node to field translation.
Comment #47
Jeyp CreditAttribution: Jeyp commentedGot the issue after upgrading to latest dev version too. Was fixed by applying patch from https://www.drupal.org/node/2098097#comment-9416315.
Comment #48
a.milkovskyCommit caused another problem. If you render title using panels everywhere - it is always in default language.
Title is rendered in my panels with ctools_set_page_token()
created a follow up issue https://www.drupal.org/node/2505311
Comment #49
TiMESPLiNTER CreditAttribution: TiMESPLiNTER as a volunteer commentedI updated today to the latest -dev version of this module because I faced the problem that the titles got not translated to another language if I used them as field in a view.
Although I updated the problem seems still to persist.
Some people above told to make a clean install. But I can't really start at the very beginning with my site. So is there a trick to get translation of the title field working with views module?
UPDATE
Okay I used the wrong field. In views only the field "Entity Translation: Title" contains the translated node title. But "Content: Title" contains always the title in node's original language. That's a different behavior then with the other fields of a content type which always display in site's current language.
Comment #50
a.milkovskySince we have entity_language() in core we don't need so complex synchronization of the translation values.
Please correct me if I am wrong.
See https://www.drupal.org/node/2542826
Comment #51
GaëlGA related issue: #2617194: Compatibility with last Title dev code
Comment #52
czigor CreditAttribution: czigor at Liip for FREITAG lab. AG commentedAnother related issue happening when entitycache, entity_translation and panelizer is used: #2768857: Overwritten titles when using entitycache, panelizer and entity_translation modules.
Comment #53
drclaw CreditAttribution: drclaw commentedComment #54
unnikrishnan CreditAttribution: unnikrishnan as a volunteer commentedI am facing this issue in my drupal 7 installation any idea how to fix this?
Thanks,
Unnikrishnan B.
Comment #55
DamienMcKenna@unnikrishnan: Start with updating your Title module to the latest -dev release.
Comment #56
victor.priceputu CreditAttribution: victor.priceputu commentedThis is still not fixed.
The module is trying to sync between the language that is being saved and the 'active language', which is the language the user is seeing the site in.
Why use language in
which is the content language (in my case 'en') when I want to save the content in a different language, say 'jp'?
I think the faulty code is in title_entity_presave() now.
Comment #57
DamienMcKenna@victor.priceutu: Please open a new issue so this can be worked on.
Comment #58
victor.priceputu CreditAttribution: victor.priceputu commentedLooks like there are 2 open already, just noticed them:
https://www.drupal.org/node/2844496
https://www.drupal.org/node/1991988