function og_field_access in Organic groups 7.2
Implements hook_field_access().
Hide group-audience fields from user's edit profile for non-privileged users.
2 string references to 'og_field_access'
- OgFieldAccessTestCase::setUp in og_field_access/
og_field_access.test - Sets up a Drupal site for running functional and integration tests.
- og_field_access_og_permission in og_field_access/
og_field_access.module - Implements hook_og_permission().
File
- ./
og.module, line 569 - Enable users to create and manage groups with roles and permissions.
Code
function og_field_access($op, $field, $entity_type, $entity, $account) {
global $user;
if (empty($entity)) {
// We are in field settings page.
return;
}
if (!$user->uid) {
// User is anonymous, and user register might try to add the
// group-audience field.
return;
}
if ($op != 'edit') {
return;
}
$field_name = $field['field_name'];
list($id, $vid, $bundle_name) = entity_extract_ids($entity_type, $entity);
$instance = field_info_instance($entity_type, $field_name, $bundle_name);
if ($field_name == OG_GROUP_FIELD) {
$wrapper = entity_metadata_wrapper($entity_type, $entity);
if ($wrapper
->getIdentifier() && !$wrapper->{OG_GROUP_FIELD}
->value()) {
// Entity isn't an active group.
return;
}
if (!empty($instance['widget']['settings']['og_hide'])) {
return FALSE;
}
return;
}
if (!og_is_group_audience_field($field_name)) {
return;
}
$field = field_info_field($field_name);
$settings = $field['settings']['handler_settings'];
// Check if we are editing the user entity.
if ($entity_type == 'user') {
if (!empty($instance['settings']['behaviors']['og_widget']['access_override'])) {
return;
}
return user_access('administer group', $account);
}
}