function _nodehierarchy_save_node in Node Hierarchy 6.2
Same name and namespace in other branches
- 6.3 nodehierarchy.module \_nodehierarchy_save_node()
- 7.4 nodehierarchy.admin.inc \_nodehierarchy_save_node()
- 7.2 nodehierarchy.module \_nodehierarchy_save_node()
Do the actual insertion or update. No permissions checking is done here.
2 calls to _nodehierarchy_save_node()
- nodehierarchy_insert_node in ./
nodehierarchy.module - Insert a node. Create parents and menus etc.
- nodehierarchy_update_node in ./
nodehierarchy.module - Update a node's parent and create menus etc.
File
- ./
nodehierarchy.module, line 678 - A module to make nodes hierarchical.
Code
function _nodehierarchy_save_node(&$node) {
// Update all of the pre-existing or default parents.
for ($i = 0; $i < count(@$node->nodehierarchy_menu_links); $i++) {
// Get the plid from the parent node id.
$node->nodehierarchy_menu_links[$i]['plid'] = _nodehierarchy_get_node_mlid($node->nodehierarchy_menu_links[$i]['pnid'], TRUE);
// Convert NULL to 0 to distinguish between a new menu item (null) and one with parent set to none (0).
$node->nodehierarchy_menu_links[$i]['plid'] = $node->nodehierarchy_menu_links[$i]['plid'] ? $node->nodehierarchy_menu_links[$i]['plid'] : 0;
// Mark the menu item to be removed if it is null (ie: not enabled and with a null parent).
if (empty($node->nodehierarchy_menu_links[$i]['enabled']) && empty($node->nodehierarchy_menu_links[$i]['plid'])) {
$node->nodehierarchy_menu_links[$i]['remove'] = TRUE;
}
// If the node type cannot be a parent, and has no parent itself, then do not save a link.
if ($node->nodehierarchy_menu_links[$i]['remove']) {
// We can only delete menu links that don't have children associated with them.
if (!_nodehierarchy_get_children_count_plid(@$node->nodehierarchy_menu_links[$i]['mlid'])) {
// Delete the the menu if it exists.
if (@$node->nodehierarchy_menu_links[$i]['mlid']) {
nodehierarchy_delete_node_nodehierarchy_menu_link($node->nodehierarchy_menu_links[$i]['mlid']);
}
// Do not save a new menu_link.
continue;
}
else {
$node->nodehierarchy_menu_links[$i]['enabled'] = $node->nodehierarchy_menu_links[$i]['plid'] = 0;
}
}
// If enabled is selected, then reverse it for hidden.
if (isset($node->nodehierarchy_menu_links[$i]['enabled'])) {
$node->nodehierarchy_menu_links[$i]['hidden'] = (int) (!$node->nodehierarchy_menu_links[$i]['enabled']);
}
// Set the menu title to the node title unless it has been customized.
if (!@$node->nodehierarchy_menu_links[$i]['customized']) {
$node->nodehierarchy_menu_links[$i]['link_title'] = $node->title;
}
if (isset($node->nodehierarchy_menu_links[$i]['description'])) {
$node->nodehierarchy_menu_links[$i]['options']['attributes']['title'] = $node->nodehierarchy_menu_links[$i]['description'];
}
// Update the paths (needed for new nodes).
$node->nodehierarchy_menu_links[$i]['nid'] = $node->nid;
$node->nodehierarchy_menu_links[$i]['link_path'] = 'node/' . $node->nid;
// Do the actual save.
_nodehierarchy_save_menu_link($node->nodehierarchy_menu_links[$i]);
}
}