diff --git a/core/core.services.yml b/core/core.services.yml index 276e19d..ddeae46 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -924,7 +924,7 @@ services: class: Drupal\Core\ParamConverter\EntityRevisionParamConverter tags: - { name: paramconverter } - arguments: ['@entity_type.manager'] + arguments: ['@entity_type.manager', '@entity.repository'] paramconverter.configentity_admin: class: Drupal\Core\ParamConverter\AdminPathConfigEntityConverter tags: diff --git a/core/lib/Drupal/Core/ParamConverter/EntityRevisionParamConverter.php b/core/lib/Drupal/Core/ParamConverter/EntityRevisionParamConverter.php index d59ae47..0d31279 100644 --- a/core/lib/Drupal/Core/ParamConverter/EntityRevisionParamConverter.php +++ b/core/lib/Drupal/Core/ParamConverter/EntityRevisionParamConverter.php @@ -2,6 +2,7 @@ namespace Drupal\Core\ParamConverter; +use Drupal\Core\Entity\EntityRepositoryInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Symfony\Component\Routing\Route; @@ -32,13 +33,23 @@ class EntityRevisionParamConverter implements ParamConverterInterface { protected $entityTypeManager; /** + * The entity repository. + * + * @var \Drupal\Core\Entity\EntityRepositoryInterface + */ + protected $entityRepository; + + /** * Creates a new EntityRevisionParamConverter instance. * * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * The entity type manager. + * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository + * The entity repository. */ - public function __construct(EntityTypeManagerInterface $entity_type_manager) { + public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityRepositoryInterface $entity_repository) { $this->entityTypeManager = $entity_type_manager; + $this->entityRepository = $entity_repository; } /** @@ -47,7 +58,7 @@ public function __construct(EntityTypeManagerInterface $entity_type_manager) { public function convert($value, $definition, $name, array $defaults) { list (, $entity_type_id) = explode(':', $definition['type'], 2); $entity = $this->entityTypeManager->getStorage($entity_type_id)->loadRevision($value); - return \Drupal::service('entity.repository')->getTranslationFromContext($entity); + return $this->entityRepository->getTranslationFromContext($entity); } /** diff --git a/core/modules/node/src/Tests/NodeLanguageViewTest.php b/core/modules/node/src/Tests/NodeLanguageViewTest.php deleted file mode 100644 index 64a7bbc..0000000 --- a/core/modules/node/src/Tests/NodeLanguageViewTest.php +++ /dev/null @@ -1,127 +0,0 @@ -bundle = 'page'; - NodeType::create([ - 'type' => $this->bundle, - 'name' => $this->bundle, - ])->save(); - } - - /** - * {@inheritdoc} - */ - function getTranslatorPermissions() { - return array_merge(parent::getTranslatorPermissions(), ['view page revisions']); - } - - /** - * {@inheritdoc} - */ - protected function setUp() { - $this->entityTypeId = 'node'; - parent::setUp(); - - $this->storage = \Drupal::entityTypeManager()->getStorage('node'); - - // Create a node. - $nid = $this->createEntity(['title' => 'First rev en title'], 'en'); - $this->node = $this->storage->load($nid); - - // Add a French translation. - $this->node->save(); - $trans = $this->node->addTranslation('fr'); - $trans->title = 'First rev fr title'; - $trans->setNewRevision(FALSE); - $trans->save(); - $this->revisionOriginal = $this->node->getRevisionId(); - - // Create a new revision. - $this->node->title = 'Second rev en title'; - $this->node->setNewRevision(TRUE); - $this->node->save(); - } - - /** - * Test revision view. - */ - function testRevisionView() { - // Get an English view of this revision. - $rev = $this->storage->loadRevision($this->revisionOriginal); - $url = $rev->toUrl('revision')->toString(); - // Should be different from regular node URL. - $this->assertNotIdentical($url, $rev->toUrl()->toString()); - $this->drupalGet($url); - $this->assertResponse(200); - // Contents should be in English, of correct revision. - $this->assertText('First rev en title'); - $this->assertNoText('Second rev en title'); - $this->assertNoText('First rev fr title'); - - // Get a French view. - $url_fr = $rev->getTranslation('fr')->toUrl('revision')->toString(); - // Should have different URL from English. - $this->assertNotIdentical($url_fr, $rev->toUrl()->toString()); - $this->assertNotIdentical($url_fr, $url); - $this->drupalGet($url_fr); - $this->assertResponse(200); - // Contents should be in French, of correct revision. - $this->assertText('First rev fr title'); - $this->assertNoText('Second rev en title'); - $this->assertNoText('First rev en title'); - } - -} diff --git a/core/modules/node/src/Tests/NodeTranslationUITest.php b/core/modules/node/src/Tests/NodeTranslationUITest.php index b4dce56..c4f04dc 100644 --- a/core/modules/node/src/Tests/NodeTranslationUITest.php +++ b/core/modules/node/src/Tests/NodeTranslationUITest.php @@ -445,4 +445,53 @@ protected function doTestTranslationEdit() { } } + /** + * Tests that revision translations are rendered properly. + */ + public function testRevisionTranslationRendering() { + $storage = \Drupal::entityTypeManager()->getStorage('node'); + + // Create a node. + $nid = $this->createEntity(['title' => 'First rev en title'], 'en'); + $node = $storage->load($nid); + $original_revision_id = $node->getRevisionId(); + + // Add a French translation. + $translation = $node->addTranslation('fr'); + $translation->title = 'First rev fr title'; + $translation->setNewRevision(FALSE); + $translation->save(); + + // Create a new revision. + $node->title = 'Second rev en title'; + $node->setNewRevision(TRUE); + $node->save(); + + // Get an English view of this revision. + $original_revision = $storage->loadRevision($original_revision_id); + $original_revision_url = $original_revision->toUrl('revision')->toString(); + + // Should be different from regular node URL. + $this->assertNotIdentical($original_revision_url, $original_revision->toUrl()->toString()); + $this->drupalGet($original_revision_url); + $this->assertResponse(200); + + // Contents should be in English, of correct revision. + $this->assertText('First rev en title'); + $this->assertNoText('First rev fr title'); + + // Get a French view. + $url_fr = $original_revision->getTranslation('fr')->toUrl('revision')->toString(); + + // Should have different URL from English. + $this->assertNotIdentical($url_fr, $original_revision->toUrl()->toString()); + $this->assertNotIdentical($url_fr, $original_revision_url); + $this->drupalGet($url_fr); + $this->assertResponse(200); + + // Contents should be in French, of correct revision. + $this->assertText('First rev fr title'); + $this->assertNoText('First rev en title'); + } + } diff --git a/core/tests/Drupal/Tests/Core/ParamConverter/EntityRevisionParamConverterTest.php b/core/tests/Drupal/Tests/Core/ParamConverter/EntityRevisionParamConverterTest.php index 3f265d8..23ac69f 100644 --- a/core/tests/Drupal/Tests/Core/ParamConverter/EntityRevisionParamConverterTest.php +++ b/core/tests/Drupal/Tests/Core/ParamConverter/EntityRevisionParamConverterTest.php @@ -3,6 +3,7 @@ namespace Drupal\Tests\Core\ParamConverter; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Entity\EntityRepositoryInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\ParamConverter\EntityRevisionParamConverter; @@ -28,7 +29,10 @@ class EntityRevisionParamConverterTest extends UnitTestCase { protected function setUp() { parent::setUp(); - $this->converter = new EntityRevisionParamConverter($this->prophesize(EntityTypeManagerInterface::class)->reveal()); + $this->converter = new EntityRevisionParamConverter( + $this->prophesize(EntityTypeManagerInterface::class)->reveal(), + $this->prophesize(EntityRepositoryInterface::class)->reveal() + ); } protected function getTestRoute() { @@ -67,7 +71,9 @@ public function testConvert() { $entity_type_manager = $this->prophesize(EntityTypeManagerInterface::class); $entity_type_manager->getStorage('test')->willReturn($storage->reveal()); - $converter = new EntityRevisionParamConverter($entity_type_manager->reveal()); + $entity_repository = $this->prophesize(EntityRepositoryInterface::class); + $entity_repository->getTranslationFromContext($entity)->willReturn($entity); + $converter = new EntityRevisionParamConverter($entity_type_manager->reveal(), $entity_repository->reveal()); $route = $this->getTestRoute(); $result = $converter->convert(1, $route->getOption('parameters')['test_revision'], 'test_revision', ['test_revision' => 1]);