diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index d807115..9506e6f 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -360,7 +360,7 @@ function template_preprocess_taxonomy_term(&$variables) { * A taxonomy term entity. */ function taxonomy_term_is_page(Term $term) { - if (in_array(\Drupal::routeMatch()->getRouteName(), ['view.taxonomy_term.page_1', 'entity.taxonomy_term.canonical']) && $page_term_id = \Drupal::routeMatch()->getRawParameter('taxonomy_term')) { + if (\Drupal::routeMatch()->getRouteName() == 'entity.taxonomy_term.canonical' && $page_term_id = \Drupal::routeMatch()->getRawParameter('taxonomy_term')) { return $page_term_id == $term->id(); } return FALSE; diff --git a/core/modules/views/src/EventSubscriber/RouteSubscriber.php b/core/modules/views/src/EventSubscriber/RouteSubscriber.php index 4b92282..f1f02b3 100644 --- a/core/modules/views/src/EventSubscriber/RouteSubscriber.php +++ b/core/modules/views/src/EventSubscriber/RouteSubscriber.php @@ -87,6 +87,8 @@ public static function getSubscribedEvents() { $events = parent::getSubscribedEvents(); $events[KernelEvents::VIEW][] = array('onHtmlPage', 75); $events[RoutingEvents::FINISHED] = array('routeRebuildFinished'); + // Ensure to run after the entity resolver subscriber + // @see \Drupal\Core\EventSubscriber\EntityRouteAlterSubscriber $events[RoutingEvents::ALTER] = ['onAlterRoutes', -175]; return $events; @@ -170,7 +172,9 @@ protected function alterRoutes(RouteCollection $collection) { $view_route_names = $display->alterRoutes($collection); $this->viewRouteNames = $view_route_names + $this->viewRouteNames; foreach ($view_route_names as $id_display => $route_name) { + $view_route_name = $this->viewsDisplayPairs[$id_display]; unset($this->viewsDisplayPairs[$id_display]); + $collection->remove("views.$view_route_name"); } } } diff --git a/core/modules/views/tests/src/Unit/EventSubscriber/RouteSubscriberTest.php b/core/modules/views/tests/src/Unit/EventSubscriber/RouteSubscriberTest.php index e48c311..16788d9 100644 --- a/core/modules/views/tests/src/Unit/EventSubscriber/RouteSubscriberTest.php +++ b/core/modules/views/tests/src/Unit/EventSubscriber/RouteSubscriberTest.php @@ -88,6 +88,7 @@ public function testRouteRebuildFinished() { */ public function testOnAlterRoutes() { $collection = new RouteCollection(); + // The first route will be overridden later. $collection->add('test_route', new Route('test_route', array('_controller' => 'Drupal\Tests\Core\Controller\TestController'))); $route_2 = new Route('test_route/example', array('_controller' => 'Drupal\Tests\Core\Controller\TestController')); $collection->add('test_route_2', $route_2); @@ -99,28 +100,39 @@ public function testOnAlterRoutes() { // The page_1 display overrides an existing route, so the dynamicRoutes // should only call the second display. $display_1->expects($this->once()) + ->method('collectRoutes') + ->willReturnCallback(function() use ($collection) { + $collection->add('views.test_id.page_1', new Route('test_route', ['_content' => 'Drupal\views\Routing\ViewPageController'])); + return ['test_id.page_1' => 'views.test_id.page_1']; + }); + $display_1->expects($this->once()) ->method('alterRoutes') - ->will($this->returnValue(array('test_id.page_1' => 'test_route'))); - $display_1->expects($this->never()) - ->method('collectRoutes'); + ->willReturn(['test_id.page_1' => 'test_route']); $display_2->expects($this->once()) - ->method('alterRoutes') - ->will($this->returnValue(array())); - $display_2->expects($this->once()) ->method('collectRoutes') - ->will($this->returnValue(array('test_id.page_2' => 'views.test_id.page_2'))); - - $this->assertNull($this->routeSubscriber->onAlterRoutes($route_event)); + ->willReturnCallback(function() use ($collection) { + $collection->add('views.test_id.page_2', new Route('test_route', ['_content' => 'Drupal\views\Routing\ViewPageController'])); + return ['test_id.page_2' => 'views.test_id.page_2']; + }); + $display_2->expects($this->once()) + ->method('alterRoutes') + ->willReturn([]); - // Ensure that after the alterRoutes the collectRoutes method is just called - // once (not for page_1 anymore). + // Ensure that even both the collectRoutes() and alterRoutes() methods + // are called on the displays, we ensure that the route first defined by + // views is dropped. $this->routeSubscriber->routes(); + $this->assertNull($this->routeSubscriber->onAlterRoutes($route_event)); $this->state->expects($this->once()) ->method('set') ->with('views.view_route_names', array('test_id.page_1' => 'test_route', 'test_id.page_2' => 'views.test_id.page_2')); + + $collection = $route_event->getRouteCollection(); + $this->assertEquals(['test_route', 'test_route_2', 'views.test_id.page_2'], array_keys($collection->all())); + $this->routeSubscriber->routeRebuildFinished(); }