diff --git a/core/lib/Drupal/Core/EventSubscriber/PathRootsSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/PathRootsSubscriber.php index 824c4e89be3..a0bd7b06400 100644 --- a/core/lib/Drupal/Core/EventSubscriber/PathRootsSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/PathRootsSubscriber.php @@ -20,7 +20,7 @@ class PathRootsSubscriber implements EventSubscriberInterface { * * @var array */ - protected $pathRoots; + protected $pathRoots = []; /** * The state key value store. @@ -58,7 +58,7 @@ class PathRootsSubscriber implements EventSubscriberInterface { */ public function onRouteFinished() { $this->state->set('router.path_roots', array_keys($this->pathRoots)); - unset($this->pathRoots); + $this->pathRoots = []; } /** diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/PathRootsSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/PathRootsSubscriberTest.php index 9e77accfe7e..96a922829a1 100644 --- a/core/tests/Drupal/Tests/Core/EventSubscriber/PathRootsSubscriberTest.php +++ b/core/tests/Drupal/Tests/Core/EventSubscriber/PathRootsSubscriberTest.php @@ -43,6 +43,11 @@ class PathRootsSubscriberTest extends UnitTestCase { * @covers ::onRouteFinished */ public function testSubscribing() { + + // Ensure that onRouteFinished can be called without throwing notices + // when no path roots got set. + $this->pathRootsSubscriber->onRouteFinished(); + $route_collection = new RouteCollection(); $route_collection->add('test_route1', new Route('/test/bar')); $route_collection->add('test_route2', new Route('/test/baz'));