You are here

public function AdminHtmlRouteProvider::getRoutes in Entity API 8

Provides routes for entities.

Parameters

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

Return value

\Symfony\Component\Routing\RouteCollection|\Symfony\Component\Routing\Route[] Returns a route collection or an array of routes keyed by name, like route_callbacks inside 'routing.yml' files.

Overrides DefaultHtmlRouteProvider::getRoutes

File

src/Routing/AdminHtmlRouteProvider.php, line 18

Class

AdminHtmlRouteProvider
Provides HTML routes for entities with administrative add/edit/delete pages.

Namespace

Drupal\entity\Routing

Code

public function getRoutes(EntityTypeInterface $entity_type) {
  $collection = parent::getRoutes($entity_type);
  $entity_type_id = $entity_type
    ->id();
  $admin_route_names = [
    "entity.{$entity_type_id}.add_page",
    "entity.{$entity_type_id}.add_form",
    "entity.{$entity_type_id}.edit_form",
    "entity.{$entity_type_id}.delete_form",
    "entity.{$entity_type_id}.delete_multiple_form",
    "entity.{$entity_type_id}.duplicate_form",
  ];
  foreach ($admin_route_names as $admin_route_name) {
    if ($route = $collection
      ->get($admin_route_name)) {
      $route
        ->setOption('_admin_route', TRUE);
    }
  }
  return $collection;
}