function nodesymlinks_item_save in NodeSymlinks 7
Same name and namespace in other branches
- 6 nodesymlinks.inc \nodesymlinks_item_save()
Save item to database.
Create alias for duplicate menulink if original node has one. Returns TRUE if saving was successfull, else returns FALSE.
Return value
menu link ID or FALSE
1 call to nodesymlinks_item_save()
- _nodesymlinks_nodeapi_insert_update in ./
nodesymlinks.inc - Implements hook_nodeapi() OP: Insert & Update.
File
- ./
nodesymlinks.inc, line 556 - Main NodeSymlinks callbacks
Code
function nodesymlinks_item_save(&$item, &$node) {
// If this function is updated, please update its counterpart in
// nodesymlinks.install, which exists to restore deleted menu_links during
// module re-enable.
$item['options']['fragment'] = empty($item['fragment']) ? '' : $item['fragment'];
if (menu_link_save($item)) {
// If the item is new, we need to save it second time - now with real mlid.
if ($item['is_new']) {
$item['link_path'] = nodesymlinks_create_item_path($item, $node);
menu_link_save($item);
}
// Because menu_links is wiped out on module disable (not Uninstall),
// we need to store this for later re-use if we detect a module re-enable.
if ($item['is_new']) {
// Save data in our permanent store.
db_insert('nodesymlinks_link_storage')
->fields(array(
'mlid' => $item['mlid'],
'nid' => $node->nid,
'item_data' => serialize($item),
))
->execute();
}
else {
// Update in permanent store.
db_update('nodesymlinks_link_storage')
->fields(array(
'nid' => $node->nid,
'item_data' => serialize($item),
))
->condition('mlid', $item['mlid'])
->execute();
}
// Creates appropriate aliases.
$item['link_path'] = nodesymlinks_create_item_path($item, $node);
nodesymlinks_item_alias_save($item, $node);
return $item['mlid'];
}
return FALSE;
}