diff --git a/core/modules/content_translation/content_translation.pages.inc b/core/modules/content_translation/content_translation.pages.inc index 44c82d0..b58909b 100644 --- a/core/modules/content_translation/content_translation.pages.inc +++ b/core/modules/content_translation/content_translation.pages.inc @@ -30,11 +30,10 @@ function content_translation_overview(EntityInterface $entity) { $rel[$name] = $entity->getSystemPath($name); } - $header = array(t('Language'), t('Translation'), t('Source language'), t('Status'), t('Operations')); + $header = array(t('Language'), t('Translation'), t('Status'), t('Operations')); $rows = array(); if (\Drupal::languageManager()->isMultilingual()) { - // Determine whether the current entity is translatable. $translatable = FALSE; foreach (field_info_instances($entity->getEntityTypeId(), $entity->bundle()) as $instance) { @@ -44,6 +43,24 @@ function content_translation_overview(EntityInterface $entity) { } } + // Collect source languages for translations (non-originals). + $language_as_source = array(); + foreach ($languages as $language) { + $langcode = $language->id; + $is_original = $langcode == $original; + if (!$is_original && isset($translations[$langcode])) { + $source = isset($entity->translation[$langcode]['source']) ? $entity->translation[$langcode]['source'] : ''; + $language_as_source[$source] = TRUE; + } + } + + // Add the source-translation column if there is more than one source value. + $show_source_column = count($language_as_source) > 1; + + if ($show_source_column) { + $header = array(t('Language'), t('Translation'), t('Source language'), t('Status'), t('Operations')); + } + foreach ($languages as $language) { $language_name = $language->name; $langcode = $language->id; @@ -125,7 +142,12 @@ function content_translation_overview(EntityInterface $entity) { $status = t('Not translated'); } - $rows[] = array($language_name, $row_title, $source_name, $status, $operations); + if ($show_source_column) { + $rows[] = array($language_name, $row_title, $source_name, $status, $operations); + } + else { + $rows[] = array($language_name, $row_title, $status, $operations); + } } } diff --git a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationUITest.php b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationUITest.php index 96bf8b2..2ebc178 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationUITest.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationUITest.php @@ -54,6 +54,8 @@ protected function doTestBasicTranslation() { $this->assertTrue($entity, 'Entity found in the database.'); $this->drupalGet($entity->getSystemPath()); $this->assertResponse(200, 'Entity URL is valid.'); + $this->drupalGet($entity->getSystemPath('drupal:content-translation-overview')); + $this->assertNoText('Source language', format_string('Source language column correctly hidden.')); $translation = $this->getTranslation($entity, $default_langcode); foreach ($values[$default_langcode] as $property => $value) { @@ -74,20 +76,27 @@ protected function doTestBasicTranslation() { $this->assertNoFieldByXPath('//select[@id="edit-langcode"]', NULL, 'Language selector correctly disabled on translations.'); } $entity = entity_load($this->entityTypeId, $this->entityId, TRUE); + $this->drupalGet($entity->getSystemPath('drupal:content-translation-overview')); + $this->assertNoText('Source language', format_string('Source language column correctly hidden.')); // Switch the source language. $langcode = 'fr'; $source_langcode = 'it'; $edit = array('source_langcode[source]' => $source_langcode); $path = $langcode . '/' . $content_translation_path . '/add/' . $default_langcode . '/' . $langcode; + // This does not save anything, it merely reloads the form and fills in the + // fields with the values from the different source language. $this->drupalPostForm($path, $edit, t('Change')); $this->assertFieldByXPath("//input[@name=\"{$this->fieldName}[0][value]\"]", $values[$source_langcode][$this->fieldName][0]['value'], 'Source language correctly switched.'); // Add another translation and mark the other ones as outdated. $values[$langcode] = $this->getNewEntityValues($langcode); $edit = $this->getEditValues($values, $langcode) + array('content_translation[retranslate]' => TRUE); + $path = $langcode . '/' . $content_translation_path . '/add/' . $source_langcode . '/' . $langcode; $this->drupalPostForm($path, $edit, $this->getFormSubmitActionForNewTranslation($entity, $langcode)); $entity = entity_load($this->entityTypeId, $this->entityId, TRUE); + $this->drupalGet($entity->getSystemPath('drupal:content-translation-overview')); + $this->assertText('Source language', format_string('Source language column correctly shown.')); // Check that the entered values have been correctly stored. foreach ($values as $langcode => $property_values) {