Implements hook_field_access().
function tmgmt_local_field_access($op, $field, $entity_type, $entity = NULL, $account = NULL) {
if ($field['field_name'] == 'tmgmt_translation_skills' && $entity_type == 'user') {
$account = !empty($account) ? $account : \Drupal::currentUser();
// If the field is just being viewed, grant access.
if ($op == 'view') {
return TRUE;
}
// User can provide transl. services and is dealing with own account.
if (!empty($entity) && $entity->uid == $account
->id()) {
return $account
->hasPermission('provide translation services');
}
// Administrators are allowed to deal with others only.
if ($account
->hasPermission('administer translation server')) {
return TRUE;
}
return FALSE;
}
}