You are here

function preview_link_entity_access in Preview Link 2.x

Same name and namespace in other branches
  1. 8 preview_link.module \preview_link_entity_access()
  2. 2.0.x preview_link.module \preview_link_entity_access()

Implements hook_entity_access().

File

./preview_link.module, line 67
Module file.

Code

function preview_link_entity_access(EntityInterface $entity, string $operation, AccountInterface $account) : AccessResultInterface {
  $neutral = AccessResult::neutral()
    ->addCacheableDependency($entity)
    ->addCacheContexts([
    'preview_link_route',
  ]);
  if ($operation !== 'view' || !$entity instanceof ContentEntityInterface) {
    return $neutral;
  }
  return \Drupal::service('access_check.preview_link')
    ->access($entity, \Drupal::routeMatch()
    ->getParameter('preview_token'));
}