You are here

protected function MenuRouterRebuildSubscriber::menuLinksRebuild in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php \Drupal\Core\EventSubscriber\MenuRouterRebuildSubscriber::menuLinksRebuild()
  2. 9 core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php \Drupal\Core\EventSubscriber\MenuRouterRebuildSubscriber::menuLinksRebuild()

Perform menu-specific rebuilding.

File

core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php, line 77

Class

MenuRouterRebuildSubscriber
Rebuilds the default menu links and runs menu-specific code if necessary.

Namespace

Drupal\Core\EventSubscriber

Code

protected function menuLinksRebuild() {
  if ($this->lock
    ->acquire(__FUNCTION__)) {
    $transaction = $this->connection
      ->startTransaction();
    try {

      // Ensure the menu links are up to date.
      $this->menuLinkManager
        ->rebuild();

      // Ignore any database replicas temporarily.
      $this->replicaKillSwitch
        ->trigger();
    } catch (\Exception $e) {
      $transaction
        ->rollBack();
      watchdog_exception('menu', $e);
    }
    $this->lock
      ->release(__FUNCTION__);
  }
  else {

    // 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.
    $this->lock
      ->wait(__FUNCTION__);
  }
}