diff --git a/core/modules/content_translation/content_translation.pages.inc b/core/modules/content_translation/content_translation.pages.inc index ac36ff7..5d3f57d 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 0816fce..854db9b 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 @@ -36,6 +36,7 @@ function testTranslationUI() { $this->doTestBasicTranslation(); $this->doTestTranslationOverview(); + $this->doTestSourceLanguageColumn(); $this->doTestOutdatedStatus(); $this->doTestPublishedStatus(); $this->doTestAuthoringInfo(); @@ -116,6 +117,56 @@ protected function doTestTranslationOverview() { } /** + * Tests that the "Source language" column is shown only when needed. + * + * The "Source language" column should only be shown when an entity has + * translations that derive from at least two source languages. + */ + protected function doTestSourceLanguageColumn() { + // Create a new test entity with original values in the default language. + $default_langcode = $this->langcodes[0]; + $values[$default_langcode] = $this->getNewEntityValues($default_langcode); + $entityId = $this->createEntity($values[$default_langcode], $default_langcode); + $entity = entity_load($this->entityTypeId, $entityId, TRUE); + $this->assertTrue($entity, 'Entity found in the database.'); + $this->drupalGet($entity->getSystemPath()); + $this->assertResponse(200, 'Entity URL is valid.'); + + // If all content is written from scratch in various languages then source + // language column should be hidden. + $this->drupalGet($entity->getSystemPath('drupal:content-translation-overview')); + $this->assertNoText('Source language', format_string('Source language column correctly hidden.')); + + // Create a number of content translations from scratch, so not based on a + // currently existing entity in a different source language. + $langcode = 'fr'; + $values[$langcode] = $this->getNewEntityValues($langcode); + $content_translation_path = $entity->getSystemPath('drupal:content-translation-overview'); + $path = $langcode . '/' . $content_translation_path . '/add/' . $default_langcode . '/' . $langcode; + $this->drupalPostForm($path, $this->getEditValues($values, $langcode), $this->getFormSubmitAction($entity)); + $entity = entity_load($this->entityTypeId, $entityId, TRUE); + + // If at most one translated version of an entity is derived from a version + // of it in another language, then Source language column should be hidden. + $this->drupalGet($entity->getSystemPath('drupal:content-translation-overview')); + $this->assertNoText('Source language', format_string('Source language column correctly hidden.')); + + // Create a new translation based on another source language. + $langcode = 'it'; + $values[$langcode] = $this->getNewEntityValues($langcode); + $source_langcode = 'fr'; + $path = $langcode . '/' . $content_translation_path . '/add/' . $source_langcode . '/' . $langcode; + $this->drupalPostForm($path, $this->getEditValues($values, $langcode), $this->getFormSubmitAction($entity)); + $entity = entity_load($this->entityTypeId, $entityId, TRUE); + + // If two or more translated versions of an entity are derived from any + // version of it in another language, then Source language column should be + // shown. + $this->drupalGet($entity->getSystemPath('drupal:content-translation-overview')); + $this->assertText('Source language', format_string('Source language column correctly shown.')); + } + + /** * Tests up-to-date status tracking. */ protected function doTestOutdatedStatus() {