You are here

protected static function ResourceTestBase::entityFieldAccess in JSON:API 8

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::entityFieldAccess()

Checks access for the given field operation on the given entity.

Parameters

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

string $field_name: The field for which to check access.

string $operation: The operation for which to check access.

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

Return value

\Drupal\Core\Access\AccessResultInterface The AccessResult.

4 calls to ResourceTestBase::entityFieldAccess()
ResourceTestBase::doTestRelationshipPost in tests/src/Functional/ResourceTestBase.php
Performs one round of relationship POST, PATCH and DELETE route testing.
ResourceTestBase::getExpectedCollectionCacheability in tests/src/Functional/ResourceTestBase.php
Computes the cacheability for a given entity collection.
ResourceTestBase::getExpectedGetRelationshipResponse in tests/src/Functional/ResourceTestBase.php
Gets an expected ResourceResponse for the given relationship.
ResourceTestBase::getExpectedRelatedResponses in tests/src/Functional/ResourceTestBase.php
Builds an array of expected related ResourceResponses, keyed by field name.

File

tests/src/Functional/ResourceTestBase.php, line 2793

Class

ResourceTestBase
Subclass this for every JSON API resource type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected static function entityFieldAccess(EntityInterface $entity, $field_name, $operation, AccountInterface $account) {
  $entity_access = static::entityAccess($entity, $operation, $account);
  $field_access = $entity->{$field_name}
    ->access($operation, $account, TRUE);
  return $entity_access
    ->andIf($field_access);
}