function menu_router_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

20 calls to menu_router_rebuild()
BlockHiddenRegionTest::testBlockNotInHiddenRegion in drupal/core/modules/block/lib/Drupal/block/Tests/BlockHiddenRegionTest.php
Tests that hidden regions do not inherit blocks when a theme is enabled.
drupal_flush_all_caches in drupal/core/includes/common.inc
Flushes all persistent caches, resets all variables, and rebuilds all data structures.
EntityTranslationUITest::enableTranslation in drupal/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationUITest.php
Enables translation for the current entity type and bundle.
ExposedFormTest::testExposedAdminUi in drupal/core/modules/views/lib/Drupal/views/Tests/Plugin/ExposedFormTest.php
Tests the admin interface of exposed filter and sort items.
field_ui_field_attach_rename_bundle in drupal/core/modules/field_ui/field_ui.module
Implements hook_field_attach_rename_bundle().

... See full list

File

drupal/core/includes/menu.inc, line 2659
API for the Drupal menu system.

Code

function menu_router_rebuild() {
  if (!lock()
    ->acquire(__FUNCTION__)) {

    // Wait for another request that is already doing this work.
    // We choose to block here since otherwise the router item may not
    // be available during routing resulting in a 404.
    lock()
      ->wait(__FUNCTION__);
    return FALSE;
  }
  $transaction = db_transaction();
  try {
    list($menu, $masks) = menu_router_build();
    _menu_router_save($menu, $masks);
    _menu_navigation_links_rebuild($menu);

    // Clear the menu, page and block caches.
    menu_cache_clear_all();
    _menu_clear_page_cache();

    // Indicate that the menu has been successfully rebuilt.
    state()
      ->delete('menu_rebuild_needed');
  } catch (Exception $e) {
    $transaction
      ->rollback();
    watchdog_exception('menu', $e);
  }
  lock()
    ->release(__FUNCTION__);
  return TRUE;
}