Problem/Motivation

When a new child entity is created using an Inline entity form embedded in a translatable parent entity in given language, the translations of the parent entity in any other language are lost (incl. the original content).

  1. Configure the following:
    • Two content types A and B
    • Entity Translation (ie. field translation) enabled on both content types
    • A few translatable fields (any type) on content type A
    • An optional non-translatable entity reference field on content type A, so an A content can reference multiple B contents.
    • The widget for the entity reference field use Inline entity form (Multiple values)
    • Enable two languages: French and English.
    • English is the site default language.
    • Enabled the devel module (optional)
  2. Create a new A content in English, without any value for the entity reference field.
  3. Create a French translation, translate the fields but do not add any value for the entity reference field.
  4. Edit the French translation, using the inline entity form, create a new referenced B content.
  5. Save the edited French translation.
  6. View the English translation of the content: The English values of the fields are used.
  7. Visit the "Translate" tab for the content: the French translation is the "original content" and there is no English translation.
  8. Go to the "Devel" tab: the English values for the translatable fields is there, the translations property of the node reflect the observation on the "Translate" tab.

Comments

pbuyle’s picture

Title: Translations of the parent entity are lost when creating a child entity with an an Inline entity form » Translations of the parent entity are lost when creating a child entity with an Inline entity form
pbuyle’s picture

Debugging the issue, I've found that, if a child entity has been created in the inline entity form, in the call EntityTranslationDefaultHandler::updateTranslations() from entity_translation_field_attach_update(), $langcode is set to the edited translation language and $this->isTranslating() is false, so EntityTranslationDefaultHandler::setOriginalLanguage() is called. This remove the original language translation from the handler's own translations data structure. Which later replace the translations stored in the database.

However, when a child entity has not been created in the inline entity form $langcode is the original translation's language. So the call to EntityTranslationDefaultHandler::setOriginalLanguage() does not remove the original translation.

Next step is to identify what causes the $langcode to have the wrong value.

pbuyle’s picture

When a child entity has been created from the edit form for the translation of the parent, in EntityTranslationDefaultHandler::updateFormLanguage, $form_state['values']['language'] is set to the edited translation language. If a child entity has not been created, $form_state['values']['language'] is set to the original translation language.

pbuyle’s picture

I tried applying the patch #1865244: Allow multiple translation handlers on the same form but it does not help (actually, that's the first thing Itried and I've continued working with the patch applied).

pbuyle’s picture

When the child entity creation form embedded in the edit form for the translation of the parent entity is submitted,
EntityTranslationDefaultHandler::entityFormLanguageWidget() is called twice on the same $form. The first time for the parent entity, the second time for the child entity. Off course, the second time the method is called, the child entity is new and is not a translation.

The first call to EntityTranslationDefaultHandler::entityFormLanguageWidget() creates $form['language'] as a select element whose default value is the language of the original translation of the parent entity. The second call to EntityTranslationDefaultHandler::entityFormLanguageWidget() resets $form['language'] to a new select element whose default value is the language of the child entity.

The easiest fix is to not enabled translation of the child entity type.

pbuyle’s picture

Issue summary: View changes

The issue happens when the translation is enabled for the child entity type.

pbuyle’s picture

Issue summary: View changes
pbuyle’s picture

I have multiple translation handler on the same form. They both add a language selector to the form, with the same key. So the second handler ends up overriding the first handler's language selector.