diff --git a/core/lib/Drupal/Core/EventSubscriber/RouterRebuildSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/RouterRebuildSubscriber.php index b11f62c..30d24e3 100644 --- a/core/lib/Drupal/Core/EventSubscriber/RouterRebuildSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/RouterRebuildSubscriber.php @@ -10,6 +10,7 @@ use Drupal\Core\Routing\RouteBuilderInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\Event\FinishRequestEvent; +use Symfony\Component\HttpKernel\Event\PostResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; /** @@ -33,7 +34,17 @@ public function __construct(RouteBuilderInterface $route_builder) { } /** - * Rebuilds routers if necessary. + * Rebuilds routers if necessary when the kernel terminates. + * + * @param \Symfony\Component\HttpKernel\Event\PostResponseEvent $event + * The event object. + */ + public function onKernelTerminate(PostResponseEvent $event) { + $this->routeBuilder->rebuildIfNeeded(); + } + + /** + * Rebuilds routers if necessary when the kernel is done with a request. * * @param \Symfony\Component\HttpKernel\Event\FinishRequestEvent $event * The event object. @@ -46,6 +57,7 @@ public function onKernelFinishRequest(FinishRequestEvent $event) { * {@inheritdoc} */ static function getSubscribedEvents() { + $events[KernelEvents::TERMINATE][] = ['onKernelTerminate', 200]; $events[KernelEvents::FINISH_REQUEST][] = ['onKernelFinishRequest', 200]; return $events; }