diff --git a/tests/title.test b/tests/title.test index 21d2139..9deced5 100644 --- a/tests/title.test +++ b/tests/title.test @@ -304,6 +304,7 @@ class TitleTranslationTestCase extends DrupalWebTestCase { 'changed' => REQUEST_TIME, ); entity_translation_get_handler('taxonomy_term', $term)->setTranslation($translation); + entity_translation_get_handler('taxonomy_term', $term)->setFormLanguage($translation_langcode); taxonomy_term_save($term); $this->assertTrue($this->checkLegacyValues($term, $original_values), 'Legacy field values correctly stored.'); $term = $this->termLoad($term->tid, $translation_langcode); @@ -312,6 +313,7 @@ class TitleTranslationTestCase extends DrupalWebTestCase { // Delete the translation. entity_translation_get_handler('taxonomy_term', $term)->removeTranslation($translation_langcode); + entity_translation_get_handler('taxonomy_term', $term)->setFormLanguage($translation_langcode); taxonomy_term_save($term); $this->assertTrue($this->checkLegacyValues($term, $original_values), 'Legacy field values correctly stored.'); $term = $this->termLoad($term->tid, $langcode); @@ -319,6 +321,7 @@ class TitleTranslationTestCase extends DrupalWebTestCase { // Make the term language neutral. entity_translation_get_handler('taxonomy_term', $term)->setOriginalLanguage(LANGUAGE_NONE); + entity_translation_get_handler('taxonomy_term', $term)->setFormLanguage(LANGUAGE_NONE); foreach ($original_values as $name => $value) { $field_name = $name . '_field'; $term->{$field_name}[LANGUAGE_NONE] = $term->{$field_name}[$langcode]; @@ -330,6 +333,7 @@ class TitleTranslationTestCase extends DrupalWebTestCase { $this->assertTrue($this->checkFieldValues($term, $original_values, LANGUAGE_NONE), 'Term original language correctly changed to the former translation language.'); // Change the term language to the former translation language. + entity_translation_get_handler('taxonomy_term', $term)->setFormLanguage($translation_langcode); entity_translation_get_handler('taxonomy_term', $term)->setOriginalLanguage($translation_langcode); foreach ($original_values as $name => $value) { $field_name = $name . '_field'; @@ -402,6 +406,23 @@ class TitleTranslationTestCase extends DrupalWebTestCase { // Check that legacy fields have the correct values. $this->assertEqual($term->name, $original_values['name'], t('Taxonomy term name correctly stored.')); $this->assertEqual($term->description, $original_values['description'], t('Taxonomy term description correctly stored.')); + + // Use the original language code as path prefix instead the translation + // language and check if the interface language doesn't affect the + // translations. + $translated_values = array( + 'name' => $this->randomName(), + 'description' => $this->randomName(), + ); + $edit = $this->editValues($translated_values, $translation_langcode); + $this->drupalPost($langcode . '/taxonomy/term/' . $term->tid . '/edit/' . $translation_langcode, $edit, t('Save')); + $term = $this->termLoad($term->tid); + $this->assertTrue($this->checkFieldValues($term, $translated_values, $translation_langcode, FALSE), t('Taxonomy term translation updated.')); + $this->assertTrue($this->checkFieldValues($term, $original_values, $langcode), t('Taxonomy term original values preserved.')); + + // Check that legacy fields have the correct values. + $this->assertEqual($term->name, $original_values['name'], t('Taxonomy term name correctly stored.')); + $this->assertEqual($term->description, $original_values['description'], t('Taxonomy term description correctly stored.')); } /** diff --git a/title.module b/title.module index 560acd1..4937389 100644 --- a/title.module +++ b/title.module @@ -150,8 +150,9 @@ function title_entity_presave($entity, $entity_type) { // need to synchronize the legacy field values into the replacing field // translations in the active language. if (module_invoke('entity_translation', 'enabled', $entity_type)) { - $langcode = title_active_language(); - $translations = entity_translation_get_handler($entity_type, $entity)->getTranslations(); + $translation_handler = entity_translation_get_handler($entity_type, $entity); + $translations = $translation_handler->getTranslations(); + $langcode = $translation_handler->getFormLanguage(); // If we are removing a translation for the active language we need to skip // reverse synchronization, as we would store empty values in the original // replacing fields immediately afterwards.