diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index 7f0c950..bca7ca6 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -165,7 +165,7 @@ public function uri($rel = 'canonical') { // If there is a template for the given relationship type, do the // placeholder replacement and use that as the path. $replacements = $this->uriPlaceholderReplacements(); - $uri['path'] = str_replace(array_keys($replacements), array_values($replacements), $template); + $uri['path'] = \Drupal::urlGenerator()->getPathFromRoute($link_templates[$rel], $replacements); // @todo Remove this once http://drupal.org/node/1888424 is in and we can // move the BC handling of / vs. no-/ to the generator. @@ -224,12 +224,16 @@ public function uri($rel = 'canonical') { protected function uriPlaceholderReplacements() { if (empty($this->uriPlaceholderReplacements)) { $this->uriPlaceholderReplacements = array( - '{entityType}' => $this->entityType(), - '{bundle}' => $this->bundle(), - '{id}' => $this->id(), - '{uuid}' => $this->uuid(), - '{' . $this->entityType() . '}' => $this->id(), + 'entityType' => $this->entityType(), + 'bundle' => $this->bundle(), + 'id' => $this->id(), + 'uuid' => $this->uuid(), + $this->entityType() => $this->id(), ); + $entity_info = \Drupal::entityManager()->getDefinition($this->entityType()); + if (isset($entity_info['bundle_entity_type'])) { + $this->uriPlaceholderReplacements[$entity_info['bundle_entity_type']] = $this->bundle(); + } } return $this->uriPlaceholderReplacements; } diff --git a/core/modules/taxonomy/config/views.view.taxonomy_term.yml b/core/modules/taxonomy/config/views.view.taxonomy_term.yml index 41ab04a..dbcae0d 100644 --- a/core/modules/taxonomy/config/views.view.taxonomy_term.yml +++ b/core/modules/taxonomy/config/views.view.taxonomy_term.yml @@ -1,22 +1,22 @@ base_field: nid base_table: node core: '8' -description: 'Customize the default taxonomy/term display.' +description: 'Content belonging to a certain taxonomy term.' status: '1' display: default: id: default display_title: Master display_plugin: default - position: '1' + position: 1 display_options: query: type: views_query options: - query_comment: '0' - disable_sql_rewrite: '0' - distinct: '0' - slave: '0' + query_comment: false + disable_sql_rewrite: false + distinct: false + slave: false query_tags: { } access: type: none @@ -28,26 +28,26 @@ display: type: basic options: submit_button: Apply - reset_button: '0' + reset_button: false reset_button_label: Reset exposed_sorts_label: 'Sort by' - expose_sort_order: '1' + expose_sort_order: true sort_asc_label: Asc sort_desc_label: Desc pager: type: mini options: - items_per_page: '10' - offset: '0' - id: '0' - total_pages: '' + items_per_page: 10 + offset: 0 + id: 0 + total_pages: 0 expose: items_per_page: '0' items_per_page_label: 'Items per page' items_per_page_options: '5, 10, 20, 40, 60' - items_per_page_options_all: '0' - items_per_page_options_all_label: 'All -' - offset: '0' + items_per_page_options_all: false + items_per_page_options_all_label: '- All -' + offset: false offset_label: Offset tags: previous: ‹‹ @@ -62,9 +62,10 @@ display: relationship: none group_type: group admin_label: '' - exposed: '0' + exposed: false expose: label: '' + provider: views created: id: created table: node_field_data @@ -74,10 +75,11 @@ display: relationship: none group_type: group admin_label: '' - exposed: '0' + exposed: false expose: label: '' granularity: second + provider: views arguments: term_node_tid_depth: id: term_node_tid_depth @@ -85,55 +87,63 @@ display: field: term_node_tid_depth default_action: 'not found' exception: - title_enable: '1' - title_enable: '1' + value: all + title_enable: true + title: All + title_enable: true title: '%1' default_argument_type: fixed summary: format: default_summary - specify_validation: '1' + specify_validation: true validate: - type: taxonomy_term + type: 'entity:taxonomy_term' + fail: 'not found' + validate_options: + access: '1' + operation: view + multiple: '1' + bundles: { } depth: '0' - break_phrase: '1' + break_phrase: true plugin_id: taxonomy_index_tid_depth relationship: none group_type: group admin_label: '' - breadcrumb_enable: '0' - breadcrumb: '' - default_argument_options: { } - default_argument_skip_url: '0' - summary_options: { } - validate_options: { } - set_breadcrumb: '0' - use_taxonomy_term_path: '0' + default_argument_options: + argument: '' + default_argument_skip_url: false + summary_options: + base_path: '' + count: '1' + items_per_page: '25' + override: false + provider: taxonomy term_node_tid_depth_modifier: id: term_node_tid_depth_modifier table: node field: term_node_tid_depth_modifier exception: - title_enable: '1' + title_enable: true default_argument_type: fixed summary: format: default_summary - specify_validation: '1' + specify_validation: true plugin_id: taxonomy_index_tid_depth_modifier relationship: none group_type: group admin_label: '' default_action: ignore - title_enable: '0' + title_enable: false title: '' - breadcrumb_enable: '0' - breadcrumb: '' default_argument_options: { } - default_argument_skip_url: '0' + default_argument_skip_url: false summary_options: { } validate: type: none fail: 'not found' validate_options: { } + provider: taxonomy filters: status_extra: id: status_extra @@ -143,14 +153,15 @@ display: expose: operator: '0' plugin_id: node_status + provider: node style: type: default options: grouping: { } row_class: '' - default_row_class: '1' - row_class_special: '1' - uses_fields: '0' + default_row_class: true + row_class_special: true + uses_fields: false row: type: 'entity:node' options: @@ -166,7 +177,7 @@ display: id: page_1 display_title: Page display_plugin: page - position: '2' + position: 2 display_options: query: type: views_query @@ -176,7 +187,7 @@ display: id: feed_1 display_title: Feed display_plugin: feed - position: '3' + position: 3 display_options: query: type: views_query @@ -184,17 +195,17 @@ display: pager: type: full options: - items_per_page: '15' - offset: '0' - id: '0' - total_pages: '' + items_per_page: 15 + offset: 0 + id: 0 + total_pages: 0 expose: items_per_page: '0' items_per_page_label: 'Items per page' items_per_page_options: '5, 10, 20, 40, 60' - items_per_page_options_all: '0' - items_per_page_options_all_label: 'All -' - offset: '0' + items_per_page_options_all: false + items_per_page_options_all_label: '- All -' + offset: false offset_label: Offset tags: previous: '‹ previous' @@ -222,4 +233,5 @@ label: 'Taxonomy term' module: taxonomy id: taxonomy_term tag: default +uuid: e0dea92e-a4c9-4442-a518-2499bfe17d73 langcode: en diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php index 19893c7..982c84c 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php @@ -236,7 +236,7 @@ public function alterRoutes(RouteCollection $collection) { // We assume that the numeric ids of the parameters match the one from // the view argument handlers. foreach ($parameters as $position => $parameter_name) { - $path = str_replace('arg_' . $argument_ids[$position], $parameter_name, $path); + $path = str_replace('{arg_' . $argument_ids[$position] . '}', '{' . $parameter_name . '}', $path); $argument_map['arg_' . $argument_ids[$position]] = $parameter_name; } // Set the corrected path and the mapping to the route object. diff --git a/core/modules/views/tests/Drupal/views/Tests/Plugin/display/PathPluginBaseTest.php b/core/modules/views/tests/Drupal/views/Tests/Plugin/display/PathPluginBaseTest.php index 8b87a45..1ac5e48 100644 --- a/core/modules/views/tests/Drupal/views/Tests/Plugin/display/PathPluginBaseTest.php +++ b/core/modules/views/tests/Drupal/views/Tests/Plugin/display/PathPluginBaseTest.php @@ -192,6 +192,43 @@ public function testAlterRoutesWithParameters() { } /** + * Tests alter routes with optional parameter in the overriding route. + */ + public function testAlterRoutesWithOptionalParameters() { + $collection = new RouteCollection(); + $collection->add('test_route', new Route('test_route/{parameter}', array('_controller' => 'Drupal\Tests\Core\Controller\TestController::content'))); + + list($view) = $this->setupViewExecutableAccessPlugin(); + + // Manually setup an argument handler. + $argument = $this->getMockBuilder('Drupal\views\Plugin\views\argument\ArgumentPluginBase') + ->disableOriginalConstructor() + ->getMock(); + $view->argument['test_id'] = $argument; + $view->argument['test_id2'] = $argument; + + $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->assertInstanceOf('\Symfony\Component\Routing\Route', $route); + $this->assertEquals('test_id', $route->getDefault('view_id')); + $this->assertEquals('page_1', $route->getDefault('display_id')); + // Ensure that the path did not changed and placeholders are respected. + $this->assertEquals('/test_route/{parameter}/{arg_test_id2}', $route->getPath()); + $this->assertEquals(array('arg_test_id' => 'parameter'), $route->getDefault('_view_argument_map')); + } + + /** * Returns some mocked view entity, view executable, and access plugin. */ protected function setupViewExecutableAccessPlugin() {