The entity_translation.modules function entity_translation_language returns a forms default language if the node is being created. This is an issue when e.g. trying to create a node in english but the createforms default language is Language neutral.

The problem lies in the entity_translation_language function.

First a default handler is created and needs to pass into the elseif clause to be able to retrieve submitted data:

function entity_translation_language($entity_type, $entity) {
  // If a form has been post, we need to check its state to verify if any form
  // translation handler is stored there. This is mainly needed when responding
  // to an AJAX request where the form language cannot be set from the page
  // callback.
  $handler = entity_translation_current_form_get_handler();

  // Make sure we always have a translation handler instance available.
  if (empty($handler)) {
    $handler = entity_translation_get_handler($entity_type, $entity);
  }
  // If a translation handler associated to the current form is found, we need
  // to update the wrapped entity. This way submitted values will be picked up.
  // Other entities may be created or saved while submitting the current one,
  // hence we need to check we are dealing with it.
  elseif ($handler->isWrappedEntity($entity_type, $entity)) {
    $langcode = $handler->getLanguage();
    $handler->setEntity($entity);
    $submitted_langcode = $handler->getLanguage();
    // If the entity language has changed we are editing the original values. In
    // this case we need to update the current form language with the submitted
    // one.
    if ($submitted_langcode != $langcode) {
      $handler->setFormLanguage($submitted_langcode);
    }
  }

  $langcode = $handler->getFormLanguage();
  return !empty($langcode) ? $langcode : $handler->getLanguage();
}

$handler->isWrappedEntity($entity_type, $entity) needs an entity id to return true which is not the case for a node in creation reaching the function. Since this statement is not reached the defalut language is returned in the function.

Setting the handler as entity_translation_get_handler($entity_type, $entity) like in the first if clause would return the correct language. Is this something that could be implemented?

Comments

David_Rothstein’s picture

Not sure if it's the same issue (maybe just related) but I created #2438615: New nodes are always created using LANGUAGE_NONE (only changed to the correct language during form submission) right now about something similar.

Note that the code seems to have changed significantly from 7.x-1.0-beta3 to the latest dev, so it's not clear if this issue is still relevant for the latest dev code.

colan’s picture

Version: 7.x-1.0-beta3 » 7.x-1.x-dev
Status: Active » Closed (works as designed)

The above code is no longer there.