function field_test_entity_field_access
Same name in other branches
- 8.9.x core/modules/field/tests/modules/field_test/field_test.field.inc \field_test_entity_field_access()
- 10 core/modules/field/tests/modules/field_test/field_test.field.inc \field_test_entity_field_access()
- 11.x core/modules/field/tests/modules/field_test/field_test.field.inc \field_test_entity_field_access()
Implements hook_entity_field_access().
File
-
core/
modules/ field/ tests/ modules/ field_test/ field_test.field.inc, line 50
Code
function field_test_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {
if ($field_definition->getName() == "field_no_{$operation}_access") {
return AccessResult::forbidden();
}
// Only grant view access to test_view_field fields when the user has
// 'view test_view_field content' permission.
if ($field_definition->getName() == 'test_view_field' && $operation == 'view') {
return AccessResult::forbiddenIf(!$account->hasPermission('view test_view_field content'))
->cachePerPermissions();
}
return AccessResult::allowed();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.