diff --git a/core/modules/node/src/Plugin/views/field/Path.php b/core/modules/node/src/Plugin/views/field/Path.php index 6895ab6..b9ffe16 100644 --- a/core/modules/node/src/Plugin/views/field/Path.php +++ b/core/modules/node/src/Plugin/views/field/Path.php @@ -68,10 +68,9 @@ public function query() { */ public function render(ResultRow $values) { $nid = $this->getValue($values, 'nid'); - $url = array( - '#markup' => \Drupal::url('entity.node.canonical', ['node' => $nid], ['absolute' => $this->options['absolute']]) + return array( + '#markup' => \Drupal::url('entity.node.canonical', ['node' => $nid], ['absolute' => $this->options['absolute']]), ); - return $url; } } diff --git a/core/modules/node/src/Tests/Views/PathPluginTest.php b/core/modules/node/src/Tests/Views/PathPluginTest.php new file mode 100644 index 0000000..e48cb87 --- /dev/null +++ b/core/modules/node/src/Tests/Views/PathPluginTest.php @@ -0,0 +1,83 @@ +drupalCreateContentType(array('type' => 'article')); + + // Create two nodes. + for ($i = 0; $i < 2; $i++) { + $this->nodes[] = $this->drupalCreateNode( + array( + 'type' => 'article', + 'body' => array( + array( + 'value' => $this->randomMachineName(42), + 'format' => filter_default_format(), + 'summary' => $this->randomMachineName(), + ), + ), + ) + ); + } + } + + /** + * Tests the node path plugin. + */ + public function testPathPlugin() { + /** @var \Drupal\Core\Render\RendererInterface $renderer */ + $renderer = $this->container->get('renderer'); + $view = Views::getView('test_node_path_plugin'); + $view->initDisplay(); + $view->setDisplay('page_1'); + $view->initStyle(); + $view->rowPlugin->options['view_mode'] = 'full'; + + // Test with view_mode full. + $output = $view->preview(); + $output = $renderer->renderRoot($output); + foreach ($this->nodes as $node) { + $this->assertTrue(strpos($output, 'This is not escaped and this is ' . $node->link('the link')) !== FALSE, 'Make sure path field rewriting is not escaped.'); + } + } + +} diff --git a/core/modules/node/tests/modules/node_test_views/test_views/views.view.test_node_path_plugin.yml b/core/modules/node/tests/modules/node_test_views/test_views/views.view.test_node_path_plugin.yml new file mode 100644 index 0000000..d937c79 --- /dev/null +++ b/core/modules/node/tests/modules/node_test_views/test_views/views.view.test_node_path_plugin.yml @@ -0,0 +1,183 @@ +uuid: fccbe0a6-be65-4789-8100-dacc4ddd3f31 +langcode: en +status: true +dependencies: + module: + - node + - user +id: test_node_path_plugin +label: test_node_path_plugin +module: views +description: '' +tag: '' +base_table: node_field_data +base_field: nid +core: 8.x +display: + default: + display_plugin: default + id: default + display_title: Master + position: 0 + display_options: + access: + type: perm + options: + perm: 'access content' + cache: + type: tag + options: { } + query: + type: views_query + options: + disable_sql_rewrite: false + distinct: false + replica: false + query_comment: '' + query_tags: { } + exposed_form: + type: basic + options: + submit_button: Apply + reset_button: false + reset_button_label: Reset + exposed_sorts_label: 'Sort by' + expose_sort_order: true + sort_asc_label: Asc + sort_desc_label: Desc + pager: + type: full + options: + items_per_page: 10 + offset: 0 + id: 0 + total_pages: null + expose: + items_per_page: false + items_per_page_label: 'Items per page' + items_per_page_options: '5, 10, 25, 50' + items_per_page_options_all: false + items_per_page_options_all_label: '- All -' + offset: false + offset_label: Offset + tags: + previous: '‹ Previous' + next: 'Next ›' + first: '« First' + last: 'Last »' + quantity: 9 + style: + type: default + row: + type: fields + fields: + path: + id: path + table: node + field: path + relationship: none + group_type: group + admin_label: '' + label: '' + exclude: false + alter: + alter_text: true + text: 'This is not escaped and this is the link.' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: false + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + absolute: false + entity_type: node + plugin_id: node_path + filters: + status: + value: true + table: node_field_data + field: status + plugin_id: boolean + entity_type: node + entity_field: status + id: status + expose: + operator: '' + group: 1 + sorts: + created: + id: created + table: node_field_data + field: created + order: DESC + entity_type: node + entity_field: created + plugin_id: date + relationship: none + group_type: group + admin_label: '' + exposed: false + expose: + label: '' + granularity: second + title: test_node_path_plugin + header: { } + footer: { } + empty: { } + relationships: { } + arguments: { } + display_extenders: { } + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_interface' + - url.query_args + - 'user.node_grants:view' + - user.permissions + tags: { } + page_1: + display_plugin: page + id: page_1 + display_title: Page + position: 1 + display_options: + display_extenders: { } + path: test-node-path-plugin + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_interface' + - url.query_args + - 'user.node_grants:view' + - user.permissions + tags: { }