_menu_link_move_children

Definition

_menu_link_move_children($item, $existing_item)
drupal/includes/menu.inc, line 2321

Description

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

Namesort iconDescription
Menu systemDefine the navigation menus, and route page requests to code based on URLs.

Code

function _menu_link_move_children($item, $existing_item) {
  $query = db_update('menu_links');

  $query->fields(array('menu_name' => $item['menu_name']));

  $p = 'p1';
  for ($i = 1; $i <= $item['depth']; $p = 'p' . ++$i) {
    $query->fields(array($p => $item[$p]));
  }
  $j = $existing_item['depth'] + 1;
  while ($i <= MENU_MAX_DEPTH && $j <= MENU_MAX_DEPTH) {
    $query->expression('p' . $i++, 'p' . $j++);
  }
  while ($i <= MENU_MAX_DEPTH) {
    $query->fields(array('p' . $i++ => 0));
  }

  $shift = $item['depth'] - $existing_item['depth'];
  if ($shift < 0) {
    $query->expression('depth', 'depth - :depth', array(':depth' => -$shift));
  }
  elseif ($shift > 0) {
    $query->expression('depth', 'depth + :depth', array(':depth' => $shift));
  }

  $query->condition('menu_name', $existing_item['menu_name']);
  $p = 'p1';
  for ($i = 1; $i <= MENU_MAX_DEPTH && $existing_item[$p]; $p = 'p' . ++$i) {
    $query->condition($p, $existing_item[$p]);
  }

  $query->execute();

  // Check the has_children status of the parent, while excluding this item.
  _menu_update_parental_status($existing_item, TRUE);
}