You are here

protected function DefaultHtmlRouteProvider::getCollectionRoute in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/Routing/DefaultHtmlRouteProvider.php \Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider::getCollectionRoute()

Gets the collection route.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type.

Return value

\Symfony\Component\Routing\Route|null The generated route, if available.

3 calls to DefaultHtmlRouteProvider::getCollectionRoute()
DefaultHtmlRouteProvider::getRoutes in core/lib/Drupal/Core/Entity/Routing/DefaultHtmlRouteProvider.php
Provides routes for entities.
TestDefaultHtmlRouteProvider::getCollectionRoute in core/tests/Drupal/Tests/Core/Entity/Routing/DefaultHtmlRouteProviderTest.php
Gets the collection route.
VocabularyRouteProvider::getCollectionRoute in core/modules/taxonomy/src/Entity/Routing/VocabularyRouteProvider.php
Gets the collection route.
2 methods override DefaultHtmlRouteProvider::getCollectionRoute()
TestDefaultHtmlRouteProvider::getCollectionRoute in core/tests/Drupal/Tests/Core/Entity/Routing/DefaultHtmlRouteProviderTest.php
Gets the collection route.
VocabularyRouteProvider::getCollectionRoute in core/modules/taxonomy/src/Entity/Routing/VocabularyRouteProvider.php
Gets the collection route.

File

core/lib/Drupal/Core/Entity/Routing/DefaultHtmlRouteProvider.php, line 318

Class

DefaultHtmlRouteProvider
Provides HTML routes for entities.

Namespace

Drupal\Core\Entity\Routing

Code

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' => $label
        ->getUntranslatedString(),
      '_title_arguments' => $label
        ->getArguments(),
      '_title_context' => $label
        ->getOption('context'),
    ])
      ->setRequirement('_permission', $admin_permission);
    return $route;
  }
}