You are here

protected static function ResourceTestBase::entityFieldAccess in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/jsonapi/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::doTestRelationshipMutation in core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
Performs one round of relationship POST, PATCH and DELETE route testing.
ResourceTestBase::getExpectedCollectionCacheability in core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
Computes the cacheability for a given entity collection.
ResourceTestBase::getExpectedGetRelationshipResponse in core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
Gets an expected ResourceResponse for the given relationship.
ResourceTestBase::getExpectedRelatedResponse in core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
Builds an expected related ResourceResponse for the given field.

File

core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php, line 3411

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 === 'edit' ? 'update' : 'view', $account);
  $field_access = $entity->{$field_name}
    ->access($operation, $account, TRUE);
  return $entity_access
    ->andIf($field_access);
}