function hook_profile_access in Profile 2 8
Control access to a user profile.
Modules may implement this hook to control whether a user has access to perform a certain operation on a profile.
Parameters
string $op: The operation being performed. One of 'view', 'edit' (being the same as 'create' or 'update'), or 'delete'.
Drupal\profile\Entity\Profile $profile: A profile to check access for.
Drupal\user\Entity\User $account: The user performing the operation; the currently logged in user by default.
Return value
bool Either a Boolean or NULL:
- FALSE to explicitly deny access. If a module denies access, no other module is able to grant access and access is denied.
- TRUE to grant access. Access is only granted if at least one module grants access and no module denies access.
- NULL or nothing to not affect the operation. If no module explicitly grants access, access is denied.
1 function implements hook_profile_access()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- profile_profile_access in ./
profile.module - Implements hook_profile_access().
File
- ./
profile.api.php, line 36 - Hooks provided by profile module.
Code
function hook_profile_access($op, Drupal\profile\Entity\Profile $profile, Drupal\user\Entity\User $account) {
// Explicitly deny access for a 'secret' profile type.
if ($profile->type == 'secret' && !user_access('custom permission')) {
return FALSE;
}
// For profiles other than the default profile grant access.
if ($profile->type != 'main' && user_access('custom permission')) {
return TRUE;
}
// In other cases do not alter access.
}