function entity_test_entity_field_access_alter

Same name and namespace in other branches
  1. 9 core/modules/system/tests/modules/entity_test/entity_test.module \entity_test_entity_field_access_alter()
  2. 8.9.x core/modules/system/tests/modules/entity_test/entity_test.module \entity_test_entity_field_access_alter()
  3. 10 core/modules/system/tests/modules/entity_test/entity_test.module \entity_test_entity_field_access_alter()

Implements hook_entity_field_access_alter().

See also

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

File

core/modules/system/tests/modules/entity_test/entity_test.module, line 438

Code

function entity_test_entity_field_access_alter(array &$grants, array $context) {
    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.