You are here

protected function FieldCollectionItemAccessControlHandler::checkAccess in Field collection 8.3

Same name and namespace in other branches
  1. 8 src/FieldCollectionItemAccessControlHandler.php \Drupal\field_collection\FieldCollectionItemAccessControlHandler::checkAccess()

Performs access checks.

This method is supposed to be overwritten by extending classes that do their own custom access checking.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity for which to check access.

string $operation: The entity operation. Usually one of 'view', 'view label', 'update' or 'delete'.

\Drupal\Core\Session\AccountInterface $account: The user for which to check access.

Return value

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

Overrides EntityAccessControlHandler::checkAccess

File

src/FieldCollectionItemAccessControlHandler.php, line 14

Class

FieldCollectionItemAccessControlHandler

Namespace

Drupal\field_collection

Code

protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {

  /** @var \Drupal\field_collection\Entity\FieldCollectionItem $entity */
  $result = parent::checkAccess($entity, $operation, $account);
  if (!$result
    ->isForbidden()) {
    $host = $entity
      ->getHost();
    if (NULL !== $host && !empty(method_exists($host, 'access'))) {
      return $host
        ->access($operation, $account, TRUE);
    }
    elseif (!$entity
      ->isNew()) {
      throw new \RuntimeException($this
        ->t('Host entity for field collection item (@id) was not set.', [
        '@id' => $entity
          ->id(),
      ]));
    }
  }
  return $result;
}