Skip to content

Instantly share code, notes, and snippets.

@tanmayk
Last active December 28, 2015 18:59
Show Gist options
  • Save tanmayk/7546871 to your computer and use it in GitHub Desktop.
Save tanmayk/7546871 to your computer and use it in GitHub Desktop.
/**
* Implements hook_field_access().
* Check if user has access for the field.
*/
function MYMODULE_field_access($op, $field, $entity_type, $entity, $account) {
if ($entity_type == 'user') {
switch ($op) {
case 'view':
global $user;
// Implement you access logic here for each field.
// $entity is user which is being viewed.
// You will get his privacy setting for single field in $entity->data['privacy_settings'][$field['field_name']].
// If you want, you can use the constants defined above.
// If current user has access to field then return TRUE, else FALSE.
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment