You are here

public function PreviewLinkHost::isToken in Preview Link 2.0.x

Same name and namespace in other branches
  1. 2.x src/PreviewLinkHost.php \Drupal\preview_link\PreviewLinkHost::isToken()

Determines if a token unlocks an entity entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: An entity.

string[] $tokens: An array of Preview Link tokens.

Return value

bool Whether if at least one provided token grants access to the entity.

Overrides PreviewLinkHostInterface::isToken

File

src/PreviewLinkHost.php, line 46

Class

PreviewLinkHost
Service for relationships between preview links and entities they unlock.

Namespace

Drupal\preview_link

Code

public function isToken(EntityInterface $entity, array $tokens) : bool {
  $count = $this->previewLinkStorage
    ->getQuery()
    ->condition('entities.target_type', $entity
    ->getEntityTypeId())
    ->condition('entities.target_id', $entity
    ->id())
    ->condition('token', $tokens, 'IN')
    ->count()
    ->execute();
  return $count > 0;
}