You are here

public function LibraryItemRouteProvider::getRoutes in Paragraphs 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

modules/paragraphs_library/src/Routing/LibraryItemRouteProvider.php, line 16

Class

LibraryItemRouteProvider
Contains routes for library item functionality.

Namespace

Drupal\paragraphs_library\Routing

Code

public function getRoutes(EntityTypeInterface $entity_type) {
  $route_collection = parent::getRoutes($entity_type);
  if ($canonical_route = $route_collection
    ->get("entity.{$entity_type->id()}.canonical")) {

    // Display library items using default theme.
    $canonical_route
      ->setOption('_admin_route', FALSE);

    // Restrict access based on permission.
    $canonical_route
      ->addRequirements([
      '_permission' => 'administer paragraphs library+create paragraph library item+edit paragraph library item',
    ]);
  }
  return $route_collection;
}