You are here

public function PreviewEnabledAccessCheck::access in Preview Link 8

Same name and namespace in other branches
  1. 2.x src/Access/PreviewEnabledAccessCheck.php \Drupal\preview_link\Access\PreviewEnabledAccessCheck::access()
  2. 2.0.x src/Access/PreviewEnabledAccessCheck.php \Drupal\preview_link\Access\PreviewEnabledAccessCheck::access()

Checks access to both the generate route and the preview route.

File

src/Access/PreviewEnabledAccessCheck.php, line 34

Class

PreviewEnabledAccessCheck
Preview link access check.

Namespace

Drupal\preview_link\Access

Code

public function access(Route $route, RouteMatchInterface $route_match) {

  // Get the entity for both the preview route and the generate preview link
  // route.
  if ($entity_type_id = $route
    ->getOption('preview_link.entity_type_id')) {
    $entity = $route_match
      ->getParameter($route
      ->getOption('preview_link.entity_type_id'));
  }
  else {
    $entity = $route_match
      ->getParameter('entity');
  }
  return AccessResult::allowedIf($this
    ->entityTypeAndBundleEnabled($entity))
    ->addCacheableDependency($entity)
    ->addCacheContexts([
    'route',
  ])
    ->addCacheableDependency($this->config);
}