menu_save

Versions
7
menu_save($menu)

Save a custom menu.

Modules should always pass a fully populated $menu when saving a custom menu, so other modules are able to output proper status or watchdog messages.

See also

menu_load()

Parameters

$menu An array representing a custom menu:

  • menu_name: The unique name of the custom menu.
  • title: The human readable menu title.
  • description: The custom menu description.
  • old_name: For existing menus, the current 'menu_name', otherwise empty. Decides whether hook_menu_insert() or hook_menu_update() will be invoked.

▾ 2 functions call menu_save()

menu_edit_menu_submit in modules/menu/menu.admin.inc
Submit function for adding or editing a custom menu.
menu_install in modules/menu/menu.install
Implements hook_install().

Code

modules/menu/menu.module, line 238

<?php
function menu_save($menu) {
  db_merge('menu_custom')
    ->key(array('menu_name' => $menu['menu_name']))
    ->fields(array(
      'title' => $menu['title'],
      'description' => $menu['description'],
    ))
    ->execute();

  // Since custom menus are keyed by name and their machine-name cannot be
  // changed, there is no real differentiation between inserting and updating a
  // menu. To overcome this, we define the existing menu_name as 'old_name' in
  // menu_edit_menu().
  // @todo Replace this condition when db_merge() returns the proper query
  //   result (insert/update).
  if (!empty($menu['old_name'])) {
    module_invoke_all('menu_update', $menu);
  }
  else {
    module_invoke_all('menu_insert', $menu);
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.