forked from fago/profile2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile.api.php
50 lines (46 loc) · 1.53 KB
/
profile.api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
* @file
* Hooks provided by profile module.
*/
/**
* @addtogroup hooks
* @{
*/
/**
* 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.
*
* @param string $op
* The operation being performed. One of 'view', 'edit' (being the same as
* 'create' or 'update'), or 'delete'.
* @param Drupal\profile\Entity\Profile $profile
* A profile to check access for.
* @param Drupal\user\Entity\User $account
* The user performing the operation; the currently logged in user by default.
*
* @return 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.
*/
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' && !\Drupal::currentUser()->hasPermission('custom permission')) {
return FALSE;
}
// For profiles other than the default profile grant access.
if ($profile->type != 'main' && \Drupal::currentUser()->hasPermission('custom permission')) {
return TRUE;
}
// In other cases do not alter access.
}
/**
* @}
*/