function domain_content_update_nodes in Domain Access 6.2
Same name and namespace in other branches
- 5 domain_content/domain_content.module \domain_content_update_nodes()
- 7.3 domain_content/domain_content.module \domain_content_update_nodes()
- 7.2 domain_content/domain_content.module \domain_content_update_nodes()
Abstraction function that lets us update access rules.
1 call to domain_content_update_nodes()
- domain_content_process_nodes in domain_content/
domain_content.module - Process the form submission.
File
- domain_content/
domain_content.module, line 294 - Editorial overview module.
Code
function domain_content_update_nodes($nids, $options) {
static $load_nodes;
// Do other modules have a stake in the node grants set by Domain Access?
if (!isset($load_nodes)) {
$load_nodes = (bool) count(module_implements('domainrecords'));
}
// If our operation is run, then we have to manually change the
// {node_access} table. The rest of the process will clear the cache,
// so this should be a safe operation.
$domain_site = $options['domain_site'];
$domains = $options['domain_id'];
$behavior = $options['behavior'];
foreach ($nids as $nid) {
// If other modules need to respond, we have to load the full node.
if ($load_nodes) {
$node = node_load($nid);
}
else {
$node = new stdClass();
$node->nid = $nid;
}
// Make sure the node is valid.
if ($node->nid > 0) {
// If modifying values, do so here.
if (!empty($behavior)) {
$current = domain_get_node_domains($node->nid);
// Add values to the current set.
if ($behavior == 1) {
if (!empty($current['domain_site'])) {
$domain_site = TRUE;
}
$domains += $current['domain_id'];
}
else {
foreach ($domains as $domain_id) {
if (isset($current['domain_id'][$domain_id])) {
unset($current['domain_id'][$domain_id]);
}
}
$domains = $current['domain_id'];
// If all affiliates is selected, remove it.
if ($domain_site) {
$domain_site = FALSE;
}
}
}
// Use our new options, as set above.
$node->domain_site = $domain_site;
$node->domains = $domains;
// Run our storage hook. This handles {domain_access} and returns
// the records we need for {node_access}.
$grants = domain_node_access_records($node);
// Get all the grants returned.
$realms = array(
'domain_site',
'domain_id',
);
foreach ($grants as $grant) {
if (!in_array($grant['realm'], $realms)) {
$realms[] = $grant['realm'];
}
}
// Delete our grants and rebuild.
foreach ($realms as $realm) {
node_access_write_grants($node, $grants, $realm);
}
}
}
// Clear the cache.
cache_clear_all();
}