Steps to reproduce:

  • Set up a site with Entity translation enabled for English and (let's say) French.
  • Create a new English node that has translations enabled, and set it's title to some kind of value. Ensure there is no French translation for this node.
  • Edit the node and set its language from English to French and save.

Expected results:
Node title remains the same.

Actual results:
Node title is set to an empty value since $node->title_field['fr'] is empty and title_field_sync_get() does not prevent this from happening.

Comments

dave reid’s picture

Status: Active » Needs review
StatusFileSize
new743 bytes

Patch attached for review.

plach’s picture

Issue tags: +Needs tests

I'm not sure this is the right fix. This way we would also prevent any legal empty value from being synced. Taxonomy term descriptions can actually be empty.

dave reid’s picture

Well it's a major problem with titles which are required, but I forgot this is also used for other things like descriptions.

plach’s picture

Priority: Normal » Major

Yes, it's a major issue. I think we should find a way to detect the language change and perform the sync with the correct langcode.

plach’s picture

Status: Needs review » Needs work

Per #4.

axe312’s picture

This problem also causes the nodes to be displayed with a blank title in /admin/content and some autocomplete fields.

Workaround:
Reopen the node and save it again. Now the titles will be displayed correctly.

The language change should be easily detectable in the hook_node_presave() (or hook_entity_presave()).

For example in the hook_node_presave, there is a copy of the old node version ($node->orginal). You can just compare the language value of the original node object with the new one to detect the language change.

jpsalter’s picture

Here is our quick workaround. Not sure where `title_original` is coming from. But, it was on our node object and it works:

function hook_node_presave($node) {
	if(empty($node->title)) {
		if(!empty($node->title_original)) {
			$node->title = $node->title_original;
		}
	}
}
plach’s picture

Status: Needs work » Needs review
StatusFileSize
new4.97 KB

I stumbled upon this while working on the integration between Title, ET and Inline Entity Forms (ouch). From my debugging it seems that this might be a core issue after all. Can you try the attached patch and check whether it fixes things for you?

Status: Needs review » Needs work

The last submitted patch, drupal-null_ fallback-1811116-8.patch, failed testing.

plach’s picture

Status: Needs work » Needs review
ezra-g’s picture

Issue tags: -Needs tests

Status: Needs review » Needs work
Issue tags: +Needs tests

The last submitted patch, drupal-null_ fallback-1811116-8.patch, failed testing.

ezra-g’s picture

Status: Needs work » Postponed

I believe this is actually a duplicate of #1086454: DATA-LOSS: Changing the Language of a node via language assignment deletes the content on the edit page. Marking "postponed" so others here can help test.

ezra-g’s picture

plach’s picture

Status: Active » Postponed (maintainer needs more info)
webwarrior’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new930 bytes

Possible solution?

kristiaanvandeneynde’s picture

Status: Needs review » Needs work

Nope, breaks synchronization of the page title.

Edit:
To clarify, all of the sudden our node (and other entity) pages would only show the title in the original language.

This is due to the fact that the original default of NULL gets overwritten because the entity indeed has a language property. This causes the Title module to sync the title in the original language, where it used to fall back to field_valid_language() and thus correctly return the content language.

michel.settembrino’s picture

Status: Needs work » Needs review
StatusFileSize
new1.29 KB

I had the same issue when I was editing webform components.
The patch I wrote (inspired by patch from #16) solved my issue.
I don't know if this is also a solution for the case described here.

joachim’s picture

Status: Needs review » Needs work

Patch #18 needs a reroll, as it's not been rolled from the right folder.

michel.settembrino’s picture

Status: Needs work » Needs review
StatusFileSize
new1.26 KB

Patch rerolled.

joachim’s picture

Status: Needs review » Needs work
+++ b/title.module
@@ -168,8 +168,23 @@ function title_field_attach_load($entity_type, $entities, $age, $options) {
+    /**
+     * When a component of a non translated webform node was changed
+     * and the current language was not the same of the webform node language,
+     * then the title of the node was emptied.
+     * Same issue as https://www.drupal.org/node/1811116
+     *
+     * Problem solved by setting the $language to the language of the node.
+     * But only when we are not editing the node
+     * otherwise this breaks synchronization of the page title.
+     */

Inline comments should be formatted with // rather than /* */.

Also, comments do not need to record historical changes to the code - they describe the code as it is now. Say what the code is doing, and describe anything that's a workaround for a problem, so for example: 'When the node is not being edited, the language must be set to yadayada to prevent yadayada.'

gaurav.kapoor’s picture

Status: Needs work » Needs review
StatusFileSize
new939 bytes

Re rolled and changed according to suggestions in #21.

pifagor’s picture

Status: Needs review » Reviewed & tested by the community

  • pifagor committed 02ef7fb on 7.x-1.x
    Issue #1811116 by michel.settembrino, plach, Dave Reid, webwarrior,...
pifagor’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

mhowe91’s picture

This patch broke the translation of titles on the webform confirmation page. A form submitted in French that redirects to the confirmation page, would display the title/ breadcrumb in English, even though the title was properly translated. Issue created - #3179509: Title is not translated on webform confirmation page

joseph.olstad’s picture

joseph.olstad’s picture