There isn't an equivalent of hook_node_access()
for users, or generically for any entity.
What you can do is checking who accessesTo check which user/%user/view using an access callback different accounts can be selected from the default oneEntity reference autocomplete, you could change the menu callback for the autocomplete.
function mymodule_menu_alter(&$items) {
if (isset($items['user$items['entityreference/%userautocomplete/view']single/%/%/%'])) {
$items['user/%user/view']['accessview']['page callback'] = 'mymodule_user_view_access';'mymodule_entity_autocomplete';
}
}
function mymodule_entity_autocomplete($type, $field_name, $entity_type, $bundle_name, $entity_id = '', $string = '') {
$field = field_info_field($field_name);
$instance = field_info_instance($entity_type, $field_name, $bundle_name);
$matches = array();
if ($type = 'user') {
// Populate $matches with the matching users the currently logged-in user can select.
return $matches;
}
return sss$type, $field, $instance, $entity_type, $entity_id, $string);
}
In this way,If then you canwant to avoid a user seesusers can view a user profile accessing itaccount directly using the link to the account, you can change the access callback for user/%user/view.
function mymodule_menu_alter(&$items) {
if (isset($items['user/%user/view'])) {
$items['user/%user/view']['access callback'] = 'mymodule_user_view_access';
}
}
The default access callback is user_view_access(), which contains the following code.
$uid = is_object($account) ? $account->uid : (int) $account;
// Never allow access to view the anonymous user account.
if ($uid) {
// Admins can view all, users can view own profiles at all times.
if ($GLOBALS['user']->uid == $uid || user_access('administer users')) {
return TRUE;
}
elseif (user_access('access user profiles')) {
// At this point, load the complete account object.
if (!is_object($account)) {
$account = user_load($uid);
}
return (is_object($account) && $account->status);
}
}
return FALSE;