Hi,
the following issue may be related, but is in fact different to #1545896: Add Entity Translation integration

Before explaining the issue, here's my setup:
My node type is Entity Translation enabled and has a Entity Reference field with Inline Entity Form as widget, allowing an unlimited number of values. Due to the lacking ET support, I've set the field itself to be translatable, but not the entities. So that every node translation has its own set of inline entities.

Adding, editing and removing entities from existing nodes works perfectly, thus changing the node language afterwards is not recommendable, but that's no problem for me.

But when I created inline entities at the same time as the parent node, I've experienced the problem, that those entities get the wrong language code set (neutral). E.g. you create a new node in German, and while not having it saved to the database, you add one or more entities to the node. As the node doesn't exist at the time of saving the entities, they and especially the entity reference field values all get the 'und' language code. So, after creating the node, the node is having a different different language (german) than the entity reference field values (neutral), which is leading to the problematic situation, that you still can view the fields, but no longer edit them on the node edit form because they are no longer appearing there.

Comments

Priority:Major» Normal

I'm also experiencing this problem, and it makes translating product titles in Drupal Commerce a real hassle.

Priority:Normal» Major

Priority:Normal» Major

I am having a similar issue as well with Inline Entity Form & Entity Translation. When I create a new node in English and then create multiple node references in the Inline Entity Form those new nodes do not get created in English. I have written a hook that seems to fix this issue.

<?php
function HOOK_inline_entity_form_entity_form_alter(&$entity_form, &$form_state) {
  global
$language;
 
$is_new = property_exists($entity_form['#entity'], 'is_new') && $entity_form['#entity']->is_new === true;
  if (
$is_new === true) {
   
$entity_form['#parent_language'] = $language->language;
   
$entity_form['#entity']->language = $language->language;
   
$form_state['build_info']['args'][0]->language = $language->language;
  }
}
?>

I can confirm this problem.

I use eck patched with #1798646: Make ECK entities translatable (entity translation integration). and inline entity form patched with #1545896: Add Entity Translation integration if I create a new eck entity through ief and the parent entity node has not been saved the fields are saved as language neutral ("und").

My first attempt was to fix this during form submit. Around here (entity.inline_entity_form.inc - Line 402)

<?php
  
if ($info['fieldable']) {
     
// Retrieve the current entity form language.
     
$langcode = entity_language($this->entityType, $entity);
     
// Handle a possible language change: new language values are inserted,
      // previous ones are deleted.
?>

But after deeper evaluation I think the problem arises already during form build. (inline_entity_form.module - inline_entity_form_field_widget_form() - Line 436)

entity_language() will return 'und' for new entities / nodes as the language for the node is collected from the form values in locale_field_entity_form_submit() So I get the language now from the complete form. Due to a missing is_new property at this place. I check against the existence of an entity id to decide if the parent is new in the attached patch. To avoid problems with the entity key I get the name for the parent id key from the entity info array for the parent beforehand.

<?php
    $parent_entity_info
= entity_get_info($element['#entity_type']);
 
// ...
  // snip....
  // ...
  // If the parent entity is new, the language is not yet set. Use the langcode
  // from the parent form in this case.
 
if (!isset($element['#entity']->$parent_entity_info['entity keys']['id'])) {
   
$parent_langcode = $form_state['complete form']['language']['#default_value'];
  } else {
   
// Get the langcode of the parent entity.
   
$parent_langcode = entity_language($element['#entity_type'], $element['#entity']);
  }
?>

Maybe someone knows a better solution. But so far I don't get any side effects. Please review.

After applying this patch, when I enter the "Add product" page for the "Product Display" entity I get this error:

Notice: Undefined index: complete form in inline_entity_form_field_widget_form() (line 457 of /home/ubuntu/Web/commerce_kickstart/profiles/commerce_kickstart/modules/contrib/inline_entity_form/inline_entity_form.module).

The "complete form" index is not included in the $form_state array. This is line 457:

    $parent_langcode = $form_state['complete form']['language']['#default_value'];

StatusFileSize
new1.66 KB

Adding additional check if the complete form exists to avoid the notice mentioned in #5.

This will avoid the notice but not fix the problem. If we don't have the complete form we cannot have a look in the parent form. We need do find another way in this case to get the parent language. I have no commerce installation here right now for testing or looking into why there is no complete form maybe someone else with the above mentioned setup can look into this.

Hi,

I have tested #6 with my Commerce 7.x-1.8 installation and Inline Entity form 7.x-1.5
Until now I think it works but I will test it more.

Thanks already for the effort!

I can confirm that #5 happens also in non commerce use cases and #6 is fixing that. The language is still saved correctly in my environment.