function domain_node_access_records in Domain Access 7.3
Same name and namespace in other branches
- 5 domain.module \domain_node_access_records()
- 6.2 domain.module \domain_node_access_records()
- 7.2 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
See also
2 calls to domain_node_access_records()
- domain_node_insert in ./
domain.module - Implements hook_node_insert().
- domain_node_update in ./
domain.module - Implements hook_node_update().
File
- ./
domain.module, line 2109 - Core module functions for the Domain Access suite.
Code
function domain_node_access_records($node) {
// 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.
$defaults = domain_get_node_defaults($node->type, array(
domain_get_domain(),
));
$node->domain_site = $defaults['domain_site'];
$node->domains = $defaults['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 publishing' 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)) {
$domains = array_filter($node->domains);
}
// Set the proper realm, for use with unpublished nodes.
$realm = 'domain_id';
if (!$node->status) {
$realm = 'domain_unpublished';
}
// Set the specified domains.
if (!empty($domains)) {
foreach (array_filter($node->domains) as $key => $value) {
$grants[] = array(
'realm' => $realm,
'gid' => $key,
'grant_view' => 1,
'grant_update' => 1,
'grant_delete' => 1,
'priority' => 0,
);
}
}
else {
$default = domain_default();
$grants[] = array(
'realm' => $realm,
'gid' => $default['domain_id'],
'grant_view' => 1,
'grant_update' => 1,
'grant_delete' => 1,
'priority' => 0,
);
}
// Store our records in the {domain_access} table.
_domain_store_grants($node->nid, $grants);
return $grants;
}