function EntityTestHooks::entityFieldAccessAlter

Implements hook_entity_field_access_alter().

See also

\Drupal\system\Tests\Entity\FieldAccessTest::testFieldAccess()

File

core/modules/system/tests/modules/entity_test/src/Hook/EntityTestHooks.php, line 324

Class

EntityTestHooks
Hook implementations for entity_test.

Namespace

Drupal\entity_test\Hook

Code

public function entityFieldAccessAlter(array &$grants, array $context) : void {
    if ($context['field_definition']->getName() == 'field_test_text' && $context['items']->value == 'access alter value') {
        $grants[':default'] = AccessResult::forbidden()->inheritCacheability($grants[':default'])
            ->addCacheableDependency($context['items']->getEntity());
    }
}

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