function domain_node_grants in Domain Access 7.3
Same name and namespace in other branches
- 5 domain.module \domain_node_grants()
- 6.2 domain.module \domain_node_grants()
- 7.2 domain.module \domain_node_grants()
Implements hook_node_grants().
Informs the node access system what permissions the user has. By design all users are in the realm defined by the currently active domain_id.
In Drupal 7, you may modify these grants in your own module, through the function hook_node_grants_alter().
@link http://api.drupal.org/api/function/hook_node_grants_alter/7
See also
domain_strict_node_grants_alter()
File
- ./
domain.module, line 2035 - Core module functions for the Domain Access suite.
Code
function domain_node_grants($account, $op) {
$_domain = domain_get_domain();
$grants = array();
// In some edge cases, the $account may not have domain information loaded,
// so get it.
domain_user_set($account);
// By design, all users can see content sent to all affiliates,
// but the $_domain['site_grant'] can be set to FALSE.
if ($op == 'view') {
if (!empty($_domain['site_grant'])) {
$grants['domain_site'][] = 0;
}
// Grant based on active domain.
if (isset($_domain['domain_id'])) {
$grants['domain_id'][] = $_domain['domain_id'];
}
// In special cases, we grant the ability to view all nodes. That is,
// we simply get out of the way of other node_access rules.
// We do this with the universal 'domain_all' grant.
if (domain_grant_all()) {
$grants = array(
'domain_all' => array(
0,
),
);
}
}
else {
$domains = $account->domain_user;
$perm = 'delete domain content';
if ($op == 'update') {
$perm = 'edit domain content';
}
if (user_access($perm, $account)) {
if (!empty($domains)) {
foreach ($domains as $id) {
if (abs($id) > 0) {
if ($id > 0) {
$grants['domain_id'][] = $id;
}
else {
$grants['domain_id'][] = 0;
}
}
}
}
}
}
// If the user may view unpublished content, then add those grants.
if (!empty($grants['domain_id']) && user_access('view unpublished domain content', $account)) {
foreach ($grants['domain_id'] as $id) {
$domains = $account->domain_user;
if (!empty($domains[$id])) {
$grants['domain_unpublished'][] = $id;
}
}
}
return $grants;
}