function FieldTestFieldHooks::entityFieldAccess
Implements hook_entity_field_access().
File
-
core/
modules/ field/ tests/ modules/ field_test/ src/ Hook/ FieldTestFieldHooks.php, line 49
Class
- FieldTestFieldHooks
- Hook implementations for field_test.
Namespace
Drupal\field_test\HookCode
public function entityFieldAccess($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.