diff --git a/core/modules/content_translation/src/ContentTranslationHandler.php b/core/modules/content_translation/src/ContentTranslationHandler.php index 2ba76e7915d..9bbfb4c8489 100644 --- a/core/modules/content_translation/src/ContentTranslationHandler.php +++ b/core/modules/content_translation/src/ContentTranslationHandler.php @@ -61,6 +61,13 @@ class ContentTranslationHandler implements ContentTranslationHandlerInterface, E */ protected $manager; + /** + * The entity type manager. + * + * @var \Drupal\Core\Entity\EntityTypeManagerInterface + */ + protected $entityTypeManager; + /** * The current user. * @@ -104,6 +111,7 @@ class ContentTranslationHandler implements ContentTranslationHandlerInterface, E $this->entityType = $entity_type; $this->languageManager = $language_manager; $this->manager = $manager; + $this->entityTypeManager = $entity_manager; $this->currentUser = $current_user; $this->fieldStorageDefinitions = $entity_manager->getLastInstalledFieldStorageDefinitions($this->entityTypeId); $this->messenger = $messenger; @@ -445,12 +453,19 @@ class ContentTranslationHandler implements ContentTranslationHandlerInterface, E ]; $translate = !$new_translation && $metadata->isOutdated(); - if (!$translate) { + $outdated_access = !ContentTranslationManager::isPendingRevisionSupportEnabled($entity->getEntityTypeId(), $entity->bundle()); + if (!$outdated_access) { + $form['content_translation']['outdated'] = [ + '#markup' => $this->t('Translations cannot be flagged as outdated when content is moderated.'), + ]; + } + elseif (!$translate) { $form['content_translation']['retranslate'] = [ '#type' => 'checkbox', '#title' => t('Flag other translations as outdated'), '#default_value' => FALSE, '#description' => t('If you made a significant change, which means the other translations should be updated, you can flag all translations of this content as outdated. This will not change any other property of them, like whether they are published or not.'), + '#access' => $outdated_access, ]; } else { @@ -459,6 +474,7 @@ class ContentTranslationHandler implements ContentTranslationHandlerInterface, E '#title' => t('This translation needs to be updated'), '#default_value' => $translate, '#description' => t('When this option is checked, this translation needs to be updated. Uncheck when the translation is up to date again.'), + '#access' => $outdated_access, ]; $form['content_translation']['#open'] = TRUE; } diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationOutdatedRevisionTranslationTest.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationOutdatedRevisionTranslationTest.php new file mode 100644 index 00000000000..d37f5d8ec4a --- /dev/null +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationOutdatedRevisionTranslationTest.php @@ -0,0 +1,89 @@ +enableContentModeration(); + } + + /** + * Tests that outdated revision translations work correctly. + */ + public function testFlagAsOutdatedHidden() { + // Create a test node. + $values = [ + 'title' => 'Test 1.1 EN', + 'moderation_state' => 'published', + ]; + $id = $this->createEntity($values, 'en'); + /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ + $entity = $this->storage->load($id); + + // Add a published Italian translation. + $add_translation_url = Url::fromRoute("entity.{$this->entityTypeId}.content_translation_add", [ + $entity->getEntityTypeId() => $id, + 'source' => 'en', + 'target' => 'it', + ], + [ + 'language' => ConfigurableLanguage::load('it'), + 'absolute' => FALSE, + ] + ); + $this->drupalGet($add_translation_url); + $this->assertFlagWidget(); + $edit = [ + 'title[0][value]' => 'Test 1.2 IT', + 'moderation_state[0][state]' => 'published', + ]; + $this->drupalPostForm(NULL, $edit, t('Save (this translation)')); + + // Add a published French translation. + $add_translation_url = Url::fromRoute("entity.{$this->entityTypeId}.content_translation_add", [ + $entity->getEntityTypeId() => $id, + 'source' => 'en', + 'target' => 'fr', + ], + [ + 'language' => ConfigurableLanguage::load('fr'), + 'absolute' => FALSE, + ] + ); + $this->drupalGet($add_translation_url); + $this->assertFlagWidget(); + $edit = [ + 'title[0][value]' => 'Test 1.3 FR', + 'moderation_state[0][state]' => 'published', + ]; + $this->drupalPostForm(NULL, $edit, t('Save (this translation)')); + + // Create an English draft. + $entity = $this->storage->loadUnchanged($id); + $en_edit_url = $this->getEditUrl($entity); + $this->drupalGet($en_edit_url); + $this->assertFlagWidget(); + } + + /** + * Checks whether the flag widget is displayed. + */ + protected function assertFlagWidget() { + $this->assertSession()->pageTextNotContains('Flag other translations as outdated'); + $this->assertSession()->pageTextContains('Translations cannot be flagged as outdated when content is moderated.'); + } + +} diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationTestBase.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationTestBase.php index d3e81a6b4ad..82715c28c29 100644 --- a/core/modules/content_translation/tests/src/Functional/ContentTranslationTestBase.php +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationTestBase.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\content_translation\Functional; +use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\Sql\SqlContentEntityStorage; use Drupal\field\Entity\FieldConfig; use Drupal\language\Entity\ConfigurableLanguage; @@ -236,4 +237,24 @@ abstract class ContentTranslationTestBase extends BrowserTestBase { return $entity->id(); } + /** + * Returns the edit URL for the specified entity. + * + * @param \Drupal\Core\Entity\ContentEntityInterface $entity + * The entity being edited. + * + * @return \Drupal\Core\Url + * The edit URL. + */ + protected function getEditUrl(ContentEntityInterface $entity) { + if ($entity->access('update', $this->loggedInUser)) { + $url = $entity->toUrl('edit-form'); + } + else { + $url = $entity->toUrl('drupal:content-translation-edit'); + $url->setRouteParameter('language', $entity->language()->getId()); + } + return $url; + } + }