diff --git a/core/modules/content_translation/content_translation.pages.inc b/core/modules/content_translation/content_translation.pages.inc index 4d2fefc..d4a7c48 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')); $rows = array(); + $show_source_column = FALSE; if (\Drupal::languageManager()->isMultilingual()) { - // Determine whether the current entity is translatable. $translatable = FALSE; foreach (\Drupal::entityManager()->getFieldDefinitions($entity->getEntityTypeId(), $entity->bundle()) as $field_definition) { @@ -44,6 +43,12 @@ function content_translation_overview(EntityInterface $entity) { } } + // Show source-language column if there are non-original source langcodes. + $additional_source_langcodes = array_filter($entity->translation, function ($translation) use ($original) { + return !empty($translation['source']) && $translation['source'] != $original; + }); + $show_source_column = !empty($additional_source_langcodes); + foreach ($languages as $language) { $language_name = $language->name; $langcode = $language->id; @@ -125,7 +130,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); + } } } @@ -135,6 +145,13 @@ function content_translation_overview(EntityInterface $entity) { // which entity this is. $build['#entity'] = $entity; + if ($show_source_column) { + $header = array(t('Language'), t('Translation'), t('Source language'), t('Status'), t('Operations')); + } + else { + $header = array(t('Language'), t('Translation'), t('Status'), t('Operations')); + } + $build['content_translation_overview'] = array( '#type' => 'table', '#header' => $header, 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..699509c 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', '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', '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', 'Source language column correctly shown.'); // Check that the entered values have been correctly stored. foreach ($values as $langcode => $property_values) {