As a module developer I would like to be able to hook into the content_access modules logic for setting the default access grants for a node and set my own so that I can create different defaults for content of the same type.
For example, I have a need to have hierarchical inheritance of grants such that a node, be default, inherits the grants of another node (referenced in my case via a node reference field). The hook code in my own module would look like this:
/**
* Implements hook_content_access_default_grant_alter().
* If no per node grants exist for a seminar, load the grants
* for the parent event if it is set.
*/
function mymodule_content_access_default_grant_alter($node, &$grants) {
if ($node->type == 'seminar' && empty($grants)) {
if (isset($node->field_event_reference) && is_array($node->field_event_reference)) {
$event = node_load($node->field_event_reference[0]['nid']);
if (is_object($event)) {
$grants = content_access_get_per_node_settings($event);
}
}
}
}
Comments
Comment #1
johnennew commentedThe attached patch demonstrates a way of adding this hook to content_access_per_node_settings function.
Comment #2
johnennew commentedswitched to needs_review
Comment #3
johnennew commentedJust remembered that there is a more elegant way to invoke an alter hook with drupal alter. Here is a new patch suggestion for comment and review.
The code in my own module would now look like this:
Comment #4
johnennew commentedSlight modification to the patch to remove the deprecated pass by reference that doen't need to be there.
Comment #5
2ndmile commentedThanks for the patch. #4 works well. I needed to be able to change view permissions for a role based on a check box on the node form.
Comment #5.0
2ndmile commentedchanged my code reference
Comment #6
gisle