function tmgmt_local_field_access in Translation Management Tool 8
Same name and namespace in other branches
- 7 translators/tmgmt_local/tmgmt_local.module \tmgmt_local_field_access()
Implements hook_field_access().
File
- translators/
tmgmt_local/ tmgmt_local.module, line 451 - Main module file for the local translation module.
Code
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;
}
}