function profile_entity_field_access in Profile 8
Implements hook_entity_field_access().
File
- ./
profile.module, line 71 - Support for configurable user profiles.
Code
function profile_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {
if ($operation == 'view' && $items && $field_definition
->getTargetEntityTypeId() == 'profile') {
if ($field_definition instanceof FieldConfigInterface) {
$is_private = $field_definition
->getThirdPartySetting('profile', 'profile_private', FALSE);
if ($is_private) {
// Users may see their own private profile fields by default, so this
// requires user granularity for caching.
/** @var \Drupal\profile\Entity\ProfileInterface $profile */
$profile = $items
->getEntity();
if ($account
->id() === $profile
->getOwnerId()) {
return AccessResult::neutral();
}
return AccessResult::forbiddenIf(!$account
->hasPermission('administer profile'));
}
}
}
return AccessResult::neutral();
}