diff --git a/includes/translation.handler.inc b/includes/translation.handler.inc index e0eb1d2..1efc6cf 100644 --- a/includes/translation.handler.inc +++ b/includes/translation.handler.inc @@ -1533,8 +1533,11 @@ class EntityTranslationDefaultHandler implements EntityTranslationHandlerInterfa /** * Update the current form language based on the submitted value. + * + * @param array $form_state + * A keyed array containing the current state of the form. */ - protected function updateFormLanguage($form_state) { + protected function updateFormLanguage(&$form_state) { // Update the form language as it might have changed. We exploit the // validation phase to be sure to act as early as possible. $language_key = $this->getLanguageKey(); @@ -1542,6 +1545,15 @@ class EntityTranslationDefaultHandler implements EntityTranslationHandlerInterfa $langcode = $form_state['values'][$language_key]; $this->setActiveLanguage($langcode); } + + // Pass entity_translation_handler_id into $form_state if it's available. + // "Locale" module uses $form_state['values'] as an entity object in its + // form submit handler. Entity language is not being determined correctly + // in case if entity_translation_handler_id is not available in form state. + $entity_type = $this->getEntityType(); + if (!empty($form_state[$entity_type]->entity_translation_handler_id)) { + $form_state['values']['entity_translation_handler_id'] = $form_state[$entity_type]->entity_translation_handler_id; + } } /** diff --git a/tests/entity_translation.test b/tests/entity_translation.test index 03950d9..67fc023 100644 --- a/tests/entity_translation.test +++ b/tests/entity_translation.test @@ -629,7 +629,7 @@ class EntityTranslationContentTranslationTestCase extends EntityTranslationTestC public static function getInfo() { return array( 'name' => 'Content and entity translation', - 'description' => 'Basic tests for nodes using both content and entity translatio.', + 'description' => 'Basic tests for nodes using both content and entity translation.', 'group' => 'Entity translation', ); } @@ -676,6 +676,37 @@ class EntityTranslationContentTranslationTestCase extends EntityTranslationTestC } /** + * Create a translation using "Content translation". + * + * @param $node + * Node of the basic page to create translation for. + * @param $title + * Title of the basic page in the specified language. + * @param $body + * Body of the basic page in the specified language. + * @param $langcode + * The language code to be assigned to the specified values. + * @return mixed + */ + function createTranslation($node, $title, $body, $langcode, $source_langcode = 'en') { + $this->drupalGet('node/add/page', array('query' => array('translation' => $node->nid, 'target' => $langcode))); + + $body_key = "body[$langcode][0][value]"; + $this->assertFieldByXPath("//textarea[@name='$body_key']", $node->body[$source_langcode][0]['value'], 'Original body value correctly populated.'); + + $edit = array(); + $edit[$body_key] = $body; + $edit['title'] = $title; + + $this->drupalPost(NULL, $edit, t('Save')); + + $translated_node = $this->drupalGetNodeByTitle($title); + $this->assertTrue(!empty($translated_node->nid), t('Translated node has been found. Translation created.')); + + return $translated_node; + } + + /** * Tests copying of source node's body value in the add translation form page. */ public function testCopyFieldsUsingContentTranslation() { @@ -692,4 +723,20 @@ class EntityTranslationContentTranslationTestCase extends EntityTranslationTestC $this->assertFieldByXPath("//textarea[@name='$body_key']", $node_body, "Body field correctly instantiated with the value of the source language."); } + /** + * Tests that fields are being saved with proper language keys when translation form is being submitted. + */ + public function testFieldsSaveUsingContentTranslation() { + // Create Basic page in English. + $node_title = $this->randomName(); + $node_body = $this->randomName(); + $node = $this->createPage($node_title, $node_body, 'en'); + + // Submit translation in Spanish. + $node_translation_title = $this->randomName(); + $node_translation_body = $this->randomName(); + $node_translation = $this->createTranslation($node, $node_translation_title, $node_translation_body, 'es'); + $this->assertTrue(isset($node_translation->body['es'][0]['value']), 'Translated body content has been saved properly.'); + } + }