function entity_test_entity_field_access_alter in Drupal 8
Same name and namespace in other branches
- 9 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 525 - Test module for the entity API providing several entity types for testing.
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());
}
}