1 menu.module menu_delete($menu)

Delete a custom menu and all contained links.

Note that this function deletes all menu links in a custom menu. While menu links derived from router paths may be restored by rebuilding the menu, all customized and custom links will be irreversibly gone. Therefore, this function should usually be called from a user interface (form submit) handler only, which allows the user to confirm the action.

menu_delete_links() will take care of clearing the page cache. Other modules should take care of their menu-related data by implementing hook_menu_delete().

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.

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

See also

menu_load()

File

core/modules/menu/menu.module, line 304
Allows administrators to customize the site's menus.

Code

function menu_delete($menu) {
  $config = config('system.core');

  // Delete all links from the menu.
  menu_delete_links($menu['menu_name']);

  // Remove menu from active menus variable.
  $active_menus = $config->get('active_menus_default') ? : array_keys(menu_get_menus());
  foreach ($active_menus as $i => $menu_name) {
    if ($menu['menu_name'] == $menu_name) {
      unset($active_menus[$i]);
      $config->set('active_menus_default', $active_menus)->save();
    }
  }

  // Delete the custom menu.
  config('menu.menu.' . $menu['menu_name'])->delete();

  menu_cache_clear_all();
  module_invoke_all('menu_delete', $menu);
}