You are here

function preview_link_entity_access in Preview Link 8

Same name and namespace in other branches
  1. 2.x 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 62
Module file.

Code

function preview_link_entity_access(EntityInterface $entity, $operation, AccountInterface $account) {
  $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'));
}