diff --git a/tests/title.test b/tests/title.test index 07ce44f..bdb96fe 100644 --- a/tests/title.test +++ b/tests/title.test @@ -420,6 +420,21 @@ 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.')); + + // Now test if the original language translation can be edited if + // interface/content is different, for example, at + // en/taxonomy/term/123/edit/it path. + $new_original_values = array( + 'name' => $this->randomName(), + 'description' => $this->randomName(), + ); + $edit = $this->editValues($new_original_values, $langcode); + $this->drupalPost('taxonomy/term/' . $term->tid . '/edit/' . $langcode, $edit, t('Save'), array( + 'language' => $languages[$translation_langcode], + )); + $term = $this->termLoad($term->tid, $langcode); + $this->assertTrue($this->checkFieldValues($term, $new_original_values, $langcode), t('Taxonomy term source updated.')); + $this->assertTrue($this->checkFieldValues($term, $translated_values, $translation_langcode, FALSE), t('Taxonomy term translation values preserved.')); } /** @@ -444,6 +459,9 @@ class TitleTranslationTestCase extends DrupalWebTestCase { $GLOBALS[$language_type] = $original_languages[$language_type]; } } + // Clear static caches again since they may now have some language related + // data. + drupal_static_reset(); return $term; } diff --git a/title.module b/title.module index 13e0ed5..8fc5995 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($entity_type, $entity); - $translations = entity_translation_get_handler($entity_type, $entity)->getTranslations(); + $handler = entity_translation_get_handler($entity_type, $entity); + $langcode = $handler->getFormLanguage(); + $translations = $handler->getTranslations(); // 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. @@ -425,7 +426,7 @@ function title_entity_sync($entity_type, &$entity, $langcode = NULL, $set = FALS list($id, , $bundle) = entity_extract_ids($entity_type, $entity); if (!isset($langcode)) { - $langcode = $set ? title_entity_language($entity_type, $entity) : title_active_language($entity_type, $entity); + $langcode = $set ? title_entity_language($entity_type, $entity) : $GLOBALS['language_content']->language; } // We do not need to perform synchronization more than once. @@ -527,38 +528,6 @@ function title_field_sync_set($entity_type, $entity, $legacy_field, $info, $lang } /** - * Returns the entity active language. - * - * The resulting value depends on the translation workflow: - * - if entity translation is used, it's form language or content language, - * - if content translation is used, it's current content language. - * - * @param string $entity_type - * The entity type. - * @param object $entity - * The entity object. - * - * @return string - * The language code. - */ -function title_active_language($entity_type, $entity) { - if ($handler = module_invoke('entity_translation', 'get_handler', $entity_type, $entity)) { - $form_language = $handler->getFormLanguage(); - if ($form_language == $handler->getLanguage() && $form_language != $GLOBALS['language_content']->language) { - // If form language is the same as entity original language, but differs - // from current content language, we assume that entity was loaded for the - // "view" purpose, so we return the content language. - // This is a bit ugly check, but there is no other way because - /* @see EntityTranslationDefaultHandler::getFormLanguage() */ - // automatically falls back to the entity "source" language. - return $GLOBALS['language_content']->language; - } - return $form_language; - } - return $GLOBALS['language_content']->language; -} - -/** * Provide the original entity language. * * If a language property is defined for the current entity we synchronize the