function menu_save_item in Drupal 4
Same name and namespace in other branches
- 5 modules/menu/menu.module \menu_save_item()
Save a menu item to the database.
Parameters
$item: The menu item to be saved. This is passed by reference, so that the newly generated $item['mid'] can be accessed after an insert takes place.
Return value
$status The operation that was performed in saving. Either SAVED_NEW (if a new menu item was created), or SAVED_UPDATED (if an existing menu item was updated).
2 calls to menu_save_item()
- menu_edit_item_save in modules/
menu.module - Save changes to a menu item into the database.
- menu_rebuild in includes/
menu.inc - Populate the database representation of the menu.
File
- modules/
menu.module, line 555 - Allows administrators to customize the site navigation menu.
Code
function menu_save_item(&$item) {
$existing_item = NULL;
// Check that the item already exists in the menu tree, if $item['mid'] is
// specified.
if (isset($item['mid'])) {
$existing_item = menu_get_item($item['mid']);
}
if ($item['mid'] && !empty($existing_item)) {
db_query("UPDATE {menu} SET pid = %d, path = '%s', title = '%s', description = '%s', weight = %d, type = %d WHERE mid = %d", $item['pid'], $item['path'], $item['title'], $item['description'], $item['weight'], $item['type'], $item['mid']);
return SAVED_UPDATED;
}
else {
$item['mid'] = db_next_id('{menu}_mid');
// Check explicitly for mid <= 2. If the database was improperly prefixed,
// this would cause a nasty infinite loop or duplicate mid errors.
// TODO: have automatic prefixing through an installer to prevent this.
while ($item['mid'] <= 2) {
$item['mid'] = db_next_id('{menu}_mid');
}
db_query("INSERT INTO {menu} (mid, pid, path, title, description, weight, type) VALUES (%d, %d, '%s', '%s', '%s', %d, %d)", $item['mid'], $item['pid'], $item['path'], $item['title'], $item['description'], $item['weight'], $item['type']);
return SAVED_NEW;
}
}