diff --git a/core/lib/Drupal/Core/Entity/Routing/DefaultHtmlRouteProvider.php b/core/lib/Drupal/Core/Entity/Routing/DefaultHtmlRouteProvider.php index 8b08d83..0ac393f 100644 --- a/core/lib/Drupal/Core/Entity/Routing/DefaultHtmlRouteProvider.php +++ b/core/lib/Drupal/Core/Entity/Routing/DefaultHtmlRouteProvider.php @@ -316,11 +316,16 @@ protected function getCollectionRoute(EntityTypeInterface $entity_type) { // If the entity type does not provide an admin permission, there is no way // to control access, so we cannot provide a route in a sensible way. if ($entity_type->hasLinkTemplate('collection') && $entity_type->hasListBuilderClass() && ($admin_permission = $entity_type->getAdminPermission())) { + /** @var \Drupal\Core\StringTranslation\TranslatableMarkup $label */ + $label = $entity_type->getCollectionLabel(); + $route = new Route($entity_type->getLinkTemplate('collection')); $route ->addDefaults([ '_entity_list' => $entity_type->id(), - '_title' => $entity_type->getCollectionLabel()->getUntranslatedString(), + '_title' => $label->getUntranslatedString(), + '_title_arguments' => $label->getArguments(), + '_title_context' => $label->getOption('context'), ]) ->setRequirement('_permission', $admin_permission); diff --git a/core/tests/Drupal/Tests/Core/Entity/Routing/DefaultHtmlRouteProviderTest.php b/core/tests/Drupal/Tests/Core/Entity/Routing/DefaultHtmlRouteProviderTest.php index b018abc..78afba2 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Routing/DefaultHtmlRouteProviderTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Routing/DefaultHtmlRouteProviderTest.php @@ -14,6 +14,7 @@ use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider; use Drupal\Core\Field\FieldStorageDefinitionInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\Tests\UnitTestCase; use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; @@ -282,13 +283,15 @@ public function providerTestGetCollectionRoute() { $entity_type4->getAdminPermission()->willReturn('administer the entity type'); $entity_type4->id()->willReturn('the_entity_type_id'); $entity_type4->getLabel()->willReturn('The entity type'); - $entity_type4->getCollectionLabel()->willReturn('Test entities'); + $entity_type4->getCollectionLabel()->willReturn(new TranslatableMarkup('Test entities')); $entity_type4->getLinkTemplate('collection')->willReturn('/the/collection/link/template'); $entity_type4->isSubclassOf(FieldableEntityInterface::class)->willReturn(FALSE); $route = (new Route('/the/collection/link/template')) ->setDefaults([ '_entity_list' => 'the_entity_type_id', '_title' => 'Test entities', + '_title_arguments' => [], + '_title_context' => '', ]) ->setRequirements([ '_permission' => 'administer the entity type',