function domain_node_access_records in Domain Access 7.2
Same name and namespace in other branches
- 5 domain.module \domain_node_access_records()
- 6.2 domain.module \domain_node_access_records()
- 7.3 domain.module \domain_node_access_records()
Implements hook_node_access_records()
Set permissions for a node to be written to the database. By design if no options are selected, the node is assigned to the main site.
Developers: if you modify these grants with hook_node_access_records_alter(), you may also need to call _domain_store_grants() to update the {domain_access} table properly.
@link http://api.drupal.org/api/function/hook_node_access_records_alter/7
@TODO: check unpublished node status handling.
See also
_domain_store_grants
File
- ./
domain.module, line 1710 - Core module functions for the Domain Access suite.
Code
function domain_node_access_records($node) {
global $_domain;
// Define the $grants array.
$grants = array();
// Check to see if the node domains were set properly.
// If not, we are dealing with an automated node process, which
// means we have to add the logic from hook_form_alter() here.
if (!isset($node->domain_site)) {
// We came from a separate source, so let's set the proper defaults.
$node->domain_site = variable_get('domain_node_' . $node->type, variable_get('domain_behavior', DOMAIN_INSTALL_RULE));
// And the currently active domain.
$node->domains = array(
$_domain['domain_id'] => $_domain['domain_id'],
);
}
// If the form is hidden, we are passed the 'domains_raw' variable.
// We need to append unique values from this variable to the existing
// stored values. See the logic for 'view domain publshing' in domain_form_alter().
if (!empty($node->domains_raw)) {
if (!isset($node->domains)) {
$node->domains = array();
}
foreach ($node->domains_raw as $value) {
// Only add this if it is not present already.
if (!in_array($value, $node->domains)) {
$node->domains[$value] = $value;
}
}
}
// If set, grant access to the core site, otherwise
// The grant must be explicitly given to a domain.
if (!empty($node->domain_site)) {
$grants[] = array(
'realm' => 'domain_site',
'gid' => 0,
'grant_view' => $node->status,
'grant_update' => 0,
'grant_delete' => 0,
'priority' => 0,
);
}
// Set the domain-specific grants.
if (!empty($node->domains)) {
foreach ($node->domains as $key => $value) {
// We can't use a 0 value in an $options list, so convert -1 to 0.
if (abs($value) > 0) {
$key == -1 ? $key = 0 : ($key = $key);
$grants[] = array(
'realm' => 'domain_id',
'gid' => $key,
'grant_view' => $node->status,
'grant_update' => 1,
'grant_delete' => 1,
'priority' => 0,
);
}
}
}
else {
$grants[] = array(
'realm' => 'domain_id',
'gid' => 0,
'grant_view' => $node->status,
'grant_update' => 1,
'grant_delete' => 1,
'priority' => 0,
);
}
// Store our records in the {domain_access} table.
_domain_store_grants($node->nid, $grants);
return $grants;
}