You are here

protected function PreviewLinkRouteProvider::getPreviewLinkRoute in Preview Link 2.x

Same name and namespace in other branches
  1. 8 src/Routing/PreviewLinkRouteProvider.php \Drupal\preview_link\Routing\PreviewLinkRouteProvider::getPreviewLinkRoute()
  2. 2.0.x src/Routing/PreviewLinkRouteProvider.php \Drupal\preview_link\Routing\PreviewLinkRouteProvider::getPreviewLinkRoute()

Gets the preview link 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 PreviewLinkRouteProvider::getPreviewLinkRoute()
PreviewLinkRouteProvider::getRoutes in src/Routing/PreviewLinkRouteProvider.php
Provides routes for entities.

File

src/Routing/PreviewLinkRouteProvider.php, line 73

Class

PreviewLinkRouteProvider
Preview Link route provider.

Namespace

Drupal\preview_link\Routing

Code

protected function getPreviewLinkRoute(EntityTypeInterface $entity_type) : ?Route {
  $entity_type_id = $entity_type
    ->id();
  $route = new Route('/preview-link/' . $entity_type_id . '/{' . $entity_type_id . '}/{preview_token}');
  $route
    ->setDefaults([
    '_controller' => 'Drupal\\preview_link\\Controller\\PreviewLinkController::preview',
    '_title_callback' => 'Drupal\\preview_link\\Controller\\PreviewLinkController::title',
  ])
    ->setRequirement('_entity_access', $entity_type_id . '.view')
    ->setRequirement('_access_preview_enabled', 'TRUE')
    ->setOption('preview_link.entity_type_id', $entity_type_id)
    ->setOption('parameters', [
    $entity_type_id => [
      'type' => 'entity:' . $entity_type_id,
      'load_latest_revision' => TRUE,
    ],
    'preview_token' => [
      'type' => 'string',
    ],
  ])
    ->setOption('_preview_link_route', TRUE);
  return $route;
}