function nodehierarchyaccess_nodeapi in Node Hierarchy 6.3
Same name and namespace in other branches
- 5 nodehierarchyaccess/nodehierarchyaccess.module \nodehierarchyaccess_nodeapi()
- 6.2 nodehierarchyaccess/nodehierarchyaccess.module \nodehierarchyaccess_nodeapi()
Implementation of hook_nodeapi().
File
- nodehierarchyaccess/
nodehierarchyaccess.module, line 22 - A module to integrate nodehierarchy and nodeaccess.
Code
function nodehierarchyaccess_nodeapi(&$node, $op) {
// don't do anything unless nodeaccess and nodehierarchy are installed and the node has an assigned parent
if (!module_exists("nodeaccess") || !module_exists("nodehierarchy")) {
return;
}
switch ($op) {
case 'presave':
// NodeHierarchy will save over the old_menu_links plid before we can get
// to it, so make a copy of it.
for ($i = 0; $i < count(@$node->nodehierarchy_old_menu_links); $i++) {
if (isset($node->nodehierarchy_menu_links[$i]['plid']) && $node->nodehierarchy_menu_links[$i]['plid'] !== $node->nodehierarchy_old_menu_links[$i]['plid']) {
$node->nodehierarchyaccess_new_plid = TRUE;
}
}
break;
case 'insert':
// Insert will always inherit the permissions from the parent node
$new_parent_nid = _nodehierarchyaccess_get_parent_nid($node->nid);
$grants = _nodehierarchyaccess_get_node_grants($new_parent_nid);
_nodehierarchyaccess_update_node_access($node, $grants);
break;
case 'update':
// Update will only inherit permissions from the parent node if the
// node's parent has changed. All changes will also be applied to the
// children nodes.
if (@$node->nodehierarchyaccess_new_plid === TRUE) {
$new_parent_nid = _nodehierarchyaccess_get_parent_nid($node->nid);
$grants = _nodehierarchyaccess_get_node_grants($new_parent_nid);
_nodehierarchyaccess_update_node_access($node, $grants);
_nodehierarchyaccess_set_descendant_grants($node->nid, $grants);
}
break;
}
}