function field_permissions_entity_field_access in Field Permissions 8
Same name and namespace in other branches
- 8.2 field_permissions.module \field_permissions_entity_field_access()
Implements hook_entity_field_access().
File
- ./
field_permissions.module, line 34 - Contains field_permissions.module.
Code
function field_permissions_entity_field_access($operation, FieldDefinitionInterface $field_definition, $account, FieldItemListInterface $items = NULL) {
$context = $operation == 'view' ? 'display' : 'edit';
if (!$field_definition
->isDisplayConfigurable($context) || empty($items)) {
return AccessResult::neutral();
}
$access_field = \Drupal::service('field_permissions.permissions_service')
->getFieldAccess($operation, $items, $account, $field_definition);
if (!$access_field) {
return AccessResult::forbidden();
}
return AccessResult::neutral();
}