1 menu.inc menu_rebuild()

Populates the database tables used by various menu functions.

This function will clear and populate the {menu_router} table, add entries to {menu_links} for new router items, and then remove stale items from {menu_links}.

Return value

TRUE if the menu was rebuilt, FALSE if another thread was rebuilding: in parallel and the current thread just waited for completion.

Related topics


core/includes/menu.inc, line 2898
API for the Backdrop menu system.


function menu_rebuild() {
  if (!lock_acquire('menu_rebuild')) {
    // Wait for another request that is already doing this work.
    // We choose to block here since otherwise the router item may not
    // be available in menu_execute_active_handler() resulting in a 404.
    return FALSE;

  $transaction = db_transaction();

  try {
    list($menu, $masks) = menu_router_build();
    _menu_router_save($menu, $masks);
    // Clear the menu, page and block caches.
    // Indicate that the menu has been successfully rebuilt.
  catch (Exception $e) {
    watchdog_exception('menu', $e);

  return TRUE;