function _nodesymlinks_nodeapi_insert_update in NodeSymlinks 6
Same name and namespace in other branches
- 7 nodesymlinks.inc \_nodesymlinks_nodeapi_insert_update()
Implementation of hook_nodeapi() OP: Insert & Update.
See also
1 call to _nodesymlinks_nodeapi_insert_update()
- nodesymlinks_nodeapi in ./
nodesymlinks.module - Implementation of hook_nodeapi().
File
- ./
nodesymlinks.inc, line 92
Code
function _nodesymlinks_nodeapi_insert_update(&$node, $op) {
$count_deleted = $count_saved = 0;
$items = isset($node->menu['nodesymlinks']['items']) ? $node->menu['nodesymlinks']['items'] : array();
$saved_items = array();
// Save all menu links from form (insert/update is handled by Menu API).
foreach ($items as &$item) {
// Load defaults and process item before save.
nodesymlinks_item_process($item, $node);
if (!$item['is_new']) {
$saved_items[] = $item['mlid'];
}
if ($mlid = nodesymlinks_item_save($item, $node)) {
++$count_saved;
if ($item['is_new']) {
$saved_items[] = $mlid;
}
}
else {
drupal_set_message(t('There was an error when saving the menu link.'), 'error');
}
}
// Detect which items exists in database, but it was not saved, delete them.
$db_items = nodesymlinks_get_items_by_nid($node->nid);
$items_to_delete = array_diff(array_keys($db_items), $saved_items);
while ($mlid = array_pop($items_to_delete)) {
nodesymlinks_item_delete($db_items[$mlid]);
++$count_deleted;
}
drupal_set_message(format_plural($count_saved, 'Saved 1 nodesymlink.', 'Saved @count nodesymlinks.') . ' ' . format_plural($count_deleted, 'Deleted 1 nodesymlink.', 'Deleted @count nodesymlinks.'));
}