class PreviewLinkHost in Preview Link 2.0.x
Same name and namespace in other branches
- 2.x src/PreviewLinkHost.php \Drupal\preview_link\PreviewLinkHost
Service for relationships between preview links and entities they unlock.
Hierarchy
- class \Drupal\preview_link\PreviewLinkHost implements PreviewLinkHostInterface
Expanded class hierarchy of PreviewLinkHost
1 string reference to 'PreviewLinkHost'
1 service uses PreviewLinkHost
File
- src/
PreviewLinkHost.php, line 13
Namespace
Drupal\preview_linkView source
class PreviewLinkHost implements PreviewLinkHostInterface {
/**
* Preview link storage.
*
* @var \Drupal\preview_link\PreviewLinkStorageInterface
*/
protected $previewLinkStorage;
/**
* PreviewLinkHost constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* Entity type manager.
*/
public function __construct(EntityTypeManagerInterface $entityTypeManager) {
$this->previewLinkStorage = $entityTypeManager
->getStorage('preview_link');
}
/**
* {@inheritdoc}
*/
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);
}
/**
* {@inheritdoc}
*/
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;
}
/**
* {@inheritdoc}
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PreviewLinkHost:: |
protected | property | Preview link storage. | |
PreviewLinkHost:: |
public | function |
Get preview links for an entity. Overrides PreviewLinkHostInterface:: |
|
PreviewLinkHost:: |
public | function |
Determines if an entity has any active preview links. Overrides PreviewLinkHostInterface:: |
|
PreviewLinkHost:: |
public | function |
Determines if a token unlocks an entity entity. Overrides PreviewLinkHostInterface:: |
|
PreviewLinkHost:: |
public | function | PreviewLinkHost constructor. |