function domain_entity_entity_access_callback in Domain Access Entity 7
Entity access callback.
See also
domain_entity_entity_info_alter(), hook_entity_info().
1 string reference to 'domain_entity_entity_access_callback'
- domain_entity_entity_info_alter in ./
domain_entity.module - Implements hook_entity_info_alter().
File
- ./
domain_entity.module, line 384 - Defines field (e.g. domain_entity) for entities, and access query alter.
Code
function domain_entity_entity_access_callback($op, $entity, $account, $entity_type) {
$allowed_entity_types = domain_entity_allowed_entity_types();
if (in_array($entity_type, array_keys($allowed_entity_types))) {
if (!variable_get('domain_entity_bypass_access_conditions', FALSE)) {
if (is_object($entity) && !in_array($op, array(
'create',
'add',
))) {
// Get accessible domains for the given user.
$accessible_domain_ids = domain_entity_get_user_available_domains($account);
$accessible_domain_ids[] = DOMAIN_ENTITY_SEND_TO_ALL;
// Get the assigned domains for the current entity.
$field_name = domain_entity_get_entity_field_name($entity_type);
$items = field_get_items($entity_type, $entity, $field_name);
$access = FALSE;
foreach ($items as $item) {
if (in_array($item['domain_id'], $accessible_domain_ids)) {
$access = TRUE;
break;
}
}
// We may restrict access, but will never widen it.
if (!$access) {
return FALSE;
}
}
}
}
// Fallback to default behavior.
$info = entity_get_info($entity_type);
if (isset($info['default access callback'])) {
$default_callback = $info['default access callback'];
return $default_callback($op, $entity, $account, $entity_type);
}
return TRUE;
}