PreviewLinkHost.php in Preview Link 2.0.x
File
src/PreviewLinkHost.php
View source
<?php
declare (strict_types=1);
namespace Drupal\preview_link;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
class PreviewLinkHost implements PreviewLinkHostInterface {
protected $previewLinkStorage;
public function __construct(EntityTypeManagerInterface $entityTypeManager) {
$this->previewLinkStorage = $entityTypeManager
->getStorage('preview_link');
}
public function getPreviewLinks(EntityInterface $entity) : array {
$ids = $this->previewLinkStorage
->getQuery()
->condition('entities.target_type', $entity
->getEntityTypeId())
->condition('entities.target_id', $entity
->id())
->execute();
return $this->previewLinkStorage
->loadMultiple($ids);
}
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;
}
public function hasPreviewLinks(EntityInterface $entity) : bool {
$count = $this->previewLinkStorage
->getQuery()
->condition('entities.target_type', $entity
->getEntityTypeId())
->condition('entities.target_id', $entity
->id())
->count()
->execute();
return $count > 0;
}
}
Classes
Name |
Description |
PreviewLinkHost |
Service for relationships between preview links and entities they unlock. |