diff --git a/core/lib/Drupal/Core/Extension/ModuleInstaller.php b/core/lib/Drupal/Core/Extension/ModuleInstaller.php index 1f8789d..af7389c 100644 --- a/core/lib/Drupal/Core/Extension/ModuleInstaller.php +++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php @@ -298,12 +298,14 @@ public function install(array $module_list, $enable_dependencies = TRUE) { // If any modules were newly installed, invoke hook_modules_installed(). if (!empty($modules_installed)) { - // Rebuild routes after installing module. This is done here on top of - // \Drupal\Core\Routing\RouteBuilder::destruct to not run into errors on - // fastCGI which executes ::destruct() after the module installation page - // was sent already. \Drupal::getContainer()->set('router.route_provider', \Drupal::service('router.route_provider.old')); - \Drupal::service('router.builder')->rebuild(); + if (!\Drupal::service('router.route_provider.lazy_builder')->hasRebuilt()) { + // Rebuild routes after installing module. This is done here on top of + // \Drupal\Core\Routing\RouteBuilder::destruct to not run into errors on + // fastCGI which executes ::destruct() after the module installation + // page was sent already. + \Drupal::service('router.builder')->rebuild(); + } $this->moduleHandler->invokeAll('modules_installed', array($modules_installed)); } diff --git a/core/lib/Drupal/Core/Routing/RouteProviderLazyBuilder.php b/core/lib/Drupal/Core/Routing/RouteProviderLazyBuilder.php index 6e80ac0..f7ed7d7 100644 --- a/core/lib/Drupal/Core/Routing/RouteProviderLazyBuilder.php +++ b/core/lib/Drupal/Core/Routing/RouteProviderLazyBuilder.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\Core\Routing\RouteProvider. + * Contains \Drupal\Core\Routing\RouteProviderLazyBuilder. */ namespace Drupal\Core\Routing; @@ -16,22 +16,33 @@ class RouteProviderLazyBuilder implements PreloadableRouteProviderInterface, PagedRouteProviderInterface { /** + * The route provider service. + * * @var \Drupal\Core\Routing\RouteProviderInterface */ protected $routeProvider; /** + * The route building service. + * * @var \Drupal\Core\Routing\RouteBuilderInterface */ protected $routeBuilder; /** + * Flag to determine if the router has been rebuilt. + * * @var bool */ protected $rebuilt = FALSE; /** + * RouteProviderLazyBuilder constructor. * + * @param \Drupal\Core\Routing\RouteProviderInterface $route_provider + * The route provider service. + * @param \Drupal\Core\Routing\RouteBuilderInterface $route_builder + * The route building service. */ public function __construct(RouteProviderInterface $route_provider, RouteBuilderInterface $route_builder) { $this->routeProvider = $route_provider; @@ -39,7 +50,10 @@ public function __construct(RouteProviderInterface $route_provider, RouteBuilder } /** + * Gets the real route provider service and rebuilds the router id necessary. * + * @return \Drupal\Core\Routing\RouteProviderInterface + * The route provider service. */ protected function getRouteProvider() { if (!$this->rebuilt) { @@ -95,7 +109,7 @@ public function getAllRoutes() { * {@inheritdoc} */ public function reset() { - // Don't call getRouteProvider as this is tricky. + // Don't call getRouteProvider as this is results in recursive rebuilds. return $this->routeProvider->reset(); } @@ -113,4 +127,14 @@ public function getRoutesCount() { return $this->getRouteProvider()->getRoutesCount(); } + /** + * Determines if the router has been rebuilt. + * + * @return bool + * TRUE is the router has been rebuilt, FALSE if not. + */ + public function hasRebuilt() { + return $this->rebuilt; + } + }