diff --git a/core/modules/taxonomy/src/Tests/TermTest.php b/core/modules/taxonomy/src/Tests/TermTest.php index 4bf221f1a664fe80749c18b82abd5616b22d1b12..71657224f2dbfd0ecb205dd321c7ec0fab4627c8 100644 --- a/core/modules/taxonomy/src/Tests/TermTest.php +++ b/core/modules/taxonomy/src/Tests/TermTest.php @@ -551,4 +551,38 @@ function testReSavingTags() { $this->assertRaw($term->getName(), 'Term is displayed after saving the node with no changes.'); } + /** + * Check the breadcrumb on edit and delete a term page. + */ + public function testTermBreadcrumbs() { + $edit = [ + 'name[0][value]' => $this->randomMachineName(14), + 'description[0][value]' => $this->randomMachineName(100), + 'parent[]' => [0], + ]; + + // Create the term. + $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add', $edit, t('Save')); + + $terms = taxonomy_term_load_multiple_by_name($edit['name[0][value]']); + $term = reset($terms); + $this->assertNotNull($term, 'Term found in database.'); + + // Check the breadcrumb on the term edit page. + $this->drupalGet('taxonomy/term/' . $term->id() . '/edit'); + $breadcrumbs = $this->cssSelect('nav.breadcrumb ol li a'); + $this->assertIdentical(count($breadcrumbs), 2, 'The breadcrumbs are present on the page.'); + $this->assertIdentical((string) $breadcrumbs[0], 'Home', 'First breadcrumb text is Home'); + $this->assertIdentical((string) $breadcrumbs[1], $term->label(), 'Second breadcrumb text is term name on term edit page.'); + $this->assertEscaped((string) $breadcrumbs[1], 'breadcrumbs displayed and escaped.'); + + // Check the breadcrumb on the term delete page. + $this->drupalGet('taxonomy/term/' . $term->id() . '/delete'); + $breadcrumbs = $this->cssSelect('nav.breadcrumb ol li a'); + $this->assertIdentical(count($breadcrumbs), 2, 'The breadcrumbs are present on the page.'); + $this->assertIdentical((string) $breadcrumbs[0], 'Home', 'First breadcrumb text is Home'); + $this->assertIdentical((string) $breadcrumbs[1], $term->label(), 'Second breadcrumb text is term name on term delete page.'); + $this->assertEscaped((string) $breadcrumbs[1], 'breadcrumbs displayed and escaped.'); + } + } diff --git a/core/modules/views/src/Plugin/views/display/PathPluginBase.php b/core/modules/views/src/Plugin/views/display/PathPluginBase.php index 738fbf4d1818d3d2dbc67af716e1834c24e2a359..402e00c68e35a80a1472aed9cdef35dd877f1562 100644 --- a/core/modules/views/src/Plugin/views/display/PathPluginBase.php +++ b/core/modules/views/src/Plugin/views/display/PathPluginBase.php @@ -270,6 +270,10 @@ public function alterRoutes(RouteCollection $collection) { // that parameter conversion options is carried over. $route->setOptions($route->getOptions() + $original_route->getOptions()); + if ($original_route->hasDefault('_title_callback')) { + $route->setDefault('_title_callback', $original_route->getDefault('_title_callback')); + } + // Set the corrected path and the mapping to the route object. $route->setOption('_view_argument_map', $argument_map); $route->setPath($path); diff --git a/core/modules/views/tests/src/Unit/Plugin/display/PathPluginBaseTest.php b/core/modules/views/tests/src/Unit/Plugin/display/PathPluginBaseTest.php index bae789a93d700cd2b8f9d20b7d94296c4d7ecfbd..90d2ae74c4691c928b4e0f42a2aa903a8afc3a71 100644 --- a/core/modules/views/tests/src/Unit/Plugin/display/PathPluginBaseTest.php +++ b/core/modules/views/tests/src/Unit/Plugin/display/PathPluginBaseTest.php @@ -260,6 +260,44 @@ public function testAlterRoute() { $this->assertSame($collection->get('test_route_2'), $route_2); } + /** + * Tests the alter route method with preexisting title callback. + */ + public function testAlterRouteWithAlterCallback() { + $collection = new RouteCollection(); + $collection->add('test_route', new Route('test_route', array('_controller' => 'Drupal\Tests\Core\Controller\TestController::content', '_title_callback' => '\Drupal\Tests\views\Unit\Plugin\display\TestController::testTitle'))); + $route_2 = new Route('test_route/example', array('_controller' => 'Drupal\Tests\Core\Controller\TestController::content')); + $collection->add('test_route_2', $route_2); + + list($view) = $this->setupViewExecutableAccessPlugin(); + + $display = array(); + $display['display_plugin'] = 'page'; + $display['id'] = 'page_1'; + $display['display_options'] = array( + 'path' => 'test_route', + ); + $this->pathPlugin->initDisplay($view, $display); + + $view_route_names = $this->pathPlugin->alterRoutes($collection); + $this->assertEquals(array('test_id.page_1' => 'test_route'), $view_route_names); + + // Ensure that the test_route is overridden. + $route = $collection->get('test_route'); + $this->assertTrue($route instanceof Route); + $this->assertEquals('test_id', $route->getDefault('view_id')); + $this->assertEquals('\Drupal\Tests\views\Unit\Plugin\display\TestController::testTitle', $route->getDefault('_title_callback')); + $this->assertEquals('page_1', $route->getDefault('display_id')); + $this->assertEquals('my views title', $route->getDefault('_title')); + + // Ensure that the test_route_2 is not overridden. + $route = $collection->get('test_route_2'); + $this->assertTrue($route instanceof Route); + $this->assertFalse($route->hasDefault('view_id')); + $this->assertFalse($route->hasDefault('display_id')); + $this->assertSame($collection->get('test_route_2'), $route_2); + } + /** * Tests the collectRoutes method with a path containing named parameters. * @@ -457,3 +495,20 @@ protected function setupViewExecutableAccessPlugin() { } } + +/** + * A page controller for use by tests in this file. + */ +class TestController { + + /** + * A page title callback. + * + * @return string + * The page title. + */ + public function testTitle() { + return 'Test title'; + } + +}