You are here

public function Item::getAccessResult in Search API 8

Checks whether a user has permission to view this item.

Parameters

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

Return value

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

Overrides ItemInterface::getAccessResult

File

src/Item/Item.php, line 436

Class

Item
Provides a default implementation for a search item.

Namespace

Drupal\search_api\Item

Code

public function getAccessResult(AccountInterface $account = NULL) {
  if (!$account) {
    $account = \Drupal::currentUser();
  }
  $uid = $account
    ->id();
  if (empty($this->accessResults[$uid])) {
    try {
      $this->accessResults[$uid] = $this
        ->getDatasource()
        ->getItemAccessResult($this
        ->getOriginalObject(), $account);
    } catch (SearchApiException $e) {
      $this->accessResults[$uid] = AccessResult::neutral('Item could not be loaded, so cannot check access');
    }
  }
  return $this->accessResults[$uid];
}