You are here

public function ContentEntity::getItemAccessResult in Search API 8

Checks whether a user has permission to view the given item.

Parameters

\Drupal\Core\TypedData\ComplexDataInterface $item: An item of this datasource's type.

\Drupal\Core\Session\AccountInterface|null $account: (optional) The user session for which to check access, or NULL to check access for the current user.

Return value

\Drupal\Core\Access\AccessResultInterface The access result.

Overrides DatasourcePluginBase::getItemAccessResult

File

src/Plugin/search_api/datasource/ContentEntity.php, line 722

Class

ContentEntity
Represents a datasource which exposes the content entities.

Namespace

Drupal\search_api\Plugin\search_api\datasource

Code

public function getItemAccessResult(ComplexDataInterface $item, AccountInterface $account = NULL) {
  $entity = $this
    ->getEntity($item);
  if ($entity) {
    return $this
      ->getEntityTypeManager()
      ->getAccessControlHandler($this
      ->getEntityTypeId())
      ->access($entity, 'view', $account, TRUE);
  }
  return AccessResult::neutral('Item is not an entity, so cannot check access');
}