profile2_og_access.module in Profile 2 7.2
Same filename and directory in other branches
Profile2 og access integration module.
File
contrib/profile2_og_access.moduleView source
<?php
/**
* @file
* Profile2 og access integration module.
*/
/**
* Implements hook_og_permission().
*/
function profile2_og_access_og_permission() {
$permissions = array();
// Generate per profile type permissions.
foreach (profile2_get_types() as $type) {
$type_name = check_plain($type->type);
$permissions += array(
"edit any {$type_name} profile" => array(
'title' => t('%type_name: Edit any profile', array(
'%type_name' => $type->label,
)),
),
"view any {$type_name} profile" => array(
'title' => t('%type_name: View any profile', array(
'%type_name' => $type->label,
)),
),
);
}
return $permissions;
}
/**
* Implements hook_profile2_access().
*
* @see profile2_profile2_access()
*/
function profile2_og_access_profile2_access($op, $profile = NULL, $account = NULL) {
if (isset($profile) && ($type_name = $profile->type) && $profile
->identifier() && $op != 'delete') {
// Check by common user og roles.
$current_user_groups = og_get_entity_groups('user', $account);
$profile_user_groups = og_get_entity_groups('user', $profile->uid);
if (!empty($current_user_groups['node']) && !empty($profile_user_groups['node'])) {
foreach ($profile_user_groups['node'] as $grp_id) {
if (in_array($grp_id, $profile_user_groups['node']) && og_user_access_entity("{$op} any {$type_name} profile", 'node', $grp_id, $account)) {
//common group found
return TRUE;
}
}
}
// Only return TRUE if og grants access. So other modules may still grant
// access in case og does not.
if (og_user_access_entity("{$op} any {$type_name} profile", 'profile2', $profile, $account)) {
return TRUE;
}
}
}
Functions
Name | Description |
---|---|
profile2_og_access_og_permission | Implements hook_og_permission(). |
profile2_og_access_profile2_access | Implements hook_profile2_access(). |