menu_links_clone

7 menu.inc menu_links_clone($links, $menu_name = NULL)
8 menu.inc menu_links_clone($links, $menu_name = NULL)

Clone an array of menu links.

Parameters

$links: An array of menu links to clone.

$menu_name: (optional) The name of a menu that the links will be cloned for. If not set, the cloned links will be in the same menu as the original set of links that were passed in.

Return value

An array of menu links with the same properties as the passed-in array, but with the link identifiers removed so that a new link will be created when any of them is passed in to menu_link_save().

See also

menu_link_save()

Related topics

2 calls to menu_links_clone()

File

includes/menu.inc, line 2913
API for the Drupal menu system.

Code

function menu_links_clone($links, $menu_name = NULL) {
  foreach ($links as &$link) {
    unset($link['mlid']);
    unset($link['plid']);
    if (isset($menu_name)) {
      $link['menu_name'] = $menu_name;
    }
  }
  return $links;
}

Comments

Menu heirarchy is broken when saving the cloned links

This will only work to clone links into a new menu that are top-level menu items. The nested links will be placed into the old menu because their 'p$x' values are still pointing to the old mlid values, and they cannot know what the new values should be, because the new mlid value for their parent may not have yet been determined.

Please see http://drupal.org/node/252200#comment-5892570

Login or register to post comments