function _menu_link_move_children in Drupal 6
Same name and namespace in other branches
- 7 includes/menu.inc \_menu_link_move_children()
Update the children of a menu link that's being moved.
The menu name, parents (p1 - p6), and depth are updated for all children of the link, and the has_children status of the previous parent is updated.
Related topics
1 call to _menu_link_move_children()
- menu_link_save in includes/
menu.inc - Save a menu link.
File
- includes/
menu.inc, line 2192 - API for the Drupal menu system.
Code
function _menu_link_move_children($item, $existing_item) {
$args[] = $item['menu_name'];
$set[] = "menu_name = '%s'";
$i = 1;
while ($i <= $item['depth']) {
$p = 'p' . $i++;
$set[] = "{$p} = %d";
$args[] = $item[$p];
}
$j = $existing_item['depth'] + 1;
while ($i <= MENU_MAX_DEPTH && $j <= MENU_MAX_DEPTH) {
$set[] = 'p' . $i++ . ' = p' . $j++;
}
while ($i <= MENU_MAX_DEPTH) {
$set[] = 'p' . $i++ . ' = 0';
}
$shift = $item['depth'] - $existing_item['depth'];
if ($shift < 0) {
$args[] = -$shift;
$set[] = 'depth = depth - %d';
}
elseif ($shift > 0) {
// The order of $set must be reversed so the new values don't overwrite the
// old ones before they can be used because "Single-table UPDATE
// assignments are generally evaluated from left to right"
// see: http://dev.mysql.com/doc/refman/5.0/en/update.html
$set = array_reverse($set);
$args = array_reverse($args);
$args[] = $shift;
$set[] = 'depth = depth + %d';
}
$where[] = "menu_name = '%s'";
$args[] = $existing_item['menu_name'];
$p = 'p1';
for ($i = 1; $i <= MENU_MAX_DEPTH && $existing_item[$p]; $p = 'p' . ++$i) {
$where[] = "{$p} = %d";
$args[] = $existing_item[$p];
}
db_query("UPDATE {menu_links} SET " . implode(', ', $set) . " WHERE " . implode(' AND ', $where), $args);
// Check the has_children status of the parent, while excluding this item.
_menu_update_parental_status($existing_item, TRUE);
}