You are here

protected function DefaultHtmlRouteProvider::getCollectionRoute in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Entity/Routing/DefaultHtmlRouteProvider.php \Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider::getCollectionRoute()
  2. 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.

1 call to DefaultHtmlRouteProvider::getCollectionRoute()
DefaultHtmlRouteProvider::getRoutes in core/lib/Drupal/Core/Entity/Routing/DefaultHtmlRouteProvider.php
Provides routes for entities.

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;
  }
}