function menu_node_nodeapi in Menu Node API 6
Implements hook_nodeapi().
File
- ./
menu_node.module, line 13 - Menu Node API Manages relationships between the {node} and {menu_links} table.
Code
function menu_node_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
$watch = array(
'insert',
'update',
'delete',
'load',
);
// Do we care about this node?
if (!in_array($op, $watch)) {
return;
}
// On delete operations, the menu item may be deleted before this
// runs, so ensure we have the data.
if ($op == 'load') {
// Ensure the menu object is loaded.
$node->menu_node_items = menu_node_get_links($node->nid);
}
$mlid = isset($node->menu['mlid']) ? $node->menu['mlid'] : NULL;
// If the node is being deleted, remove all records.
if ($op == 'delete') {
menu_node_delete($node);
}
else {
// If we have a record to insert, then do so now.
if (empty($node->menu['delete']) && !empty($mlid)) {
menu_node_save($node->nid, $mlid);
}
else {
if (!empty($mlid)) {
menu_node_delete($node->nid, $mlid);
}
}
}
}