function ResourceTestBase::entityAccess

Same name in other branches
  1. 9 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::entityAccess()
  2. 8.9.x core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::entityAccess()
  3. 11.x core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::entityAccess()

Checks access for the given operation on the given entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity for which to check field 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.

3 calls to ResourceTestBase::entityAccess()
ResourceTestBase::doTestSparseFieldSets in core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
Tests sparse field sets.
ResourceTestBase::entityFieldAccess in core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
Checks access for the given field operation on the given entity.
ResourceTestBase::getExpectedCollectionCacheability in core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
Computes the cacheability for a given entity collection.
3 methods override ResourceTestBase::entityAccess()
CommentTest::entityAccess in core/modules/jsonapi/tests/src/Functional/CommentTest.php
Checks access for the given operation on the given entity.
EditorTest::entityAccess in core/modules/jsonapi/tests/src/Functional/EditorTest.php
Checks access for the given operation on the given entity.
FieldConfigTest::entityAccess in core/modules/jsonapi/tests/src/Functional/FieldConfigTest.php
Checks access for the given operation on the given entity.

File

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

Class

ResourceTestBase
Subclass this for every JSON:API resource type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected static function entityAccess(EntityInterface $entity, $operation, AccountInterface $account) {
    // The default entity access control handler assumes that permissions do not
    // change during the lifetime of a request and caches access results.
    // However, we're changing permissions during a test run and need fresh
    // results, so reset the cache.
    \Drupal::entityTypeManager()->getAccessControlHandler($entity->getEntityTypeId())
        ->resetCache();
    return $entity->access($operation, $account, TRUE);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.