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..036bd9d 100644 --- a/title.module +++ b/title.module @@ -145,20 +145,26 @@ function title_entity_presave($entity, $entity_type) { $entity_langcode = title_entity_language($entity_type, $entity); $langcode = $entity_langcode; + file_put_contents('/tmp/boo.txt', $langcode . "\n#####\n", FILE_APPEND); + file_put_contents('/tmp/boo.txt', 'boo' . "\n#####\n", FILE_APPEND); // If Entity Translation is enabled and the entity type is transltable,we need // to check if we have a translation for the current active language. If so we // 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(); + file_put_contents('/tmp/boo.txt', $langcode . "\n", FILE_APPEND); // 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. if (!isset($translations->data[$langcode])) { + file_put_contents('/tmp/boo.txt', $langcode . "\n" . print_r(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), 1), FILE_APPEND); $langcode = isset($translations->hook[$langcode]['hook']) && $translations->hook[$langcode]['hook'] == 'delete' ? FALSE : $entity_langcode; } } + file_put_contents('/tmp/boo.txt', $langcode . "\n#####\n", FILE_APPEND); // Perform reverse synchronization to retain any change in the legacy field // values. We must avoid doing this twice as we might overwrite the already