From fb27c45f6a75a0a2a528b9b50aa8085f515c018f Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Wed, 13 Aug 2014 18:15:35 -0700 Subject: [PATCH] =?UTF-8?q?Issue=20#2252739=20by=20G=C3=A1bor=20Hojtsy,=20?= =?UTF-8?q?rbayliss:=20Fixed=20Taxonomy=20field=20handler=20fatal=20error?= =?UTF-8?q?=20in=20linking=20to=20terms,=20cannot=20create=20taxonomy=20vi?= =?UTF-8?q?ews=20with=20defaults.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Plugin/views/field/Taxonomy.php | 9 +- .../src/Tests/Views/TaxonomyFieldTidTest.php | 36 ++++ .../views.view.test_taxonomy_tid_field.yml | 176 ++++++++++++++++++ 3 files changed, 215 insertions(+), 6 deletions(-) create mode 100644 core/modules/taxonomy/src/Tests/Views/TaxonomyFieldTidTest.php create mode 100644 core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.test_taxonomy_tid_field.yml diff --git a/core/modules/taxonomy/src/Plugin/views/field/Taxonomy.php b/core/modules/taxonomy/src/Plugin/views/field/Taxonomy.php index 59ced2d861d..2a7dd736d62 100644 --- a/core/modules/taxonomy/src/Plugin/views/field/Taxonomy.php +++ b/core/modules/taxonomy/src/Plugin/views/field/Taxonomy.php @@ -77,12 +77,9 @@ class Taxonomy extends FieldPluginBase { * Returns a string for the link text. */ protected function renderLink($data, ResultRow $values) { - $tid = $this->getValue($values, 'tid'); - if (!empty($this->options['link_to_taxonomy']) && !empty($tid) && $data !== NULL && $data !== '') { - $term = entity_create('taxonomy_term', array( - 'tid' => $tid, - 'vid' => $this->getValue($values, 'vid'), - )); + $term = $this->getEntity($values); + + if (!empty($this->options['link_to_taxonomy']) && $term && $data !== NULL && $data !== '') { $this->options['alter']['make_link'] = TRUE; $this->options['alter']['path'] = $term->getSystemPath(); } diff --git a/core/modules/taxonomy/src/Tests/Views/TaxonomyFieldTidTest.php b/core/modules/taxonomy/src/Tests/Views/TaxonomyFieldTidTest.php new file mode 100644 index 00000000000..03b29798887 --- /dev/null +++ b/core/modules/taxonomy/src/Tests/Views/TaxonomyFieldTidTest.php @@ -0,0 +1,36 @@ +executeView($view); + + $actual = $view->field['name']->advancedRender($view->result[0]); + $expected = l($this->term1->label(), $this->term1->getSystemPath()); + + $this->assertEqual($expected, $actual); + } + +} diff --git a/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.test_taxonomy_tid_field.yml b/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.test_taxonomy_tid_field.yml new file mode 100644 index 00000000000..6f2bf4ffd1b --- /dev/null +++ b/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.test_taxonomy_tid_field.yml @@ -0,0 +1,176 @@ +langcode: en +status: true +dependencies: + module: + - taxonomy +id: test_taxonomy_tid_field +label: test_taxonomy_tid_field +module: views +description: '' +tag: '' +base_table: taxonomy_term_data +base_field: tid +core: 8.x +display: + default: + display_plugin: default + id: default + display_title: Master + position: 0 + provider: views + display_options: + access: + type: perm + options: + perm: 'access content' + provider: user + dependencies: { } + cache: + type: none + options: { } + provider: views + dependencies: { } + query: + type: views_query + options: + disable_sql_rewrite: false + distinct: false + replica: false + query_comment: false + query_tags: { } + provider: views + dependencies: { } + 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 + provider: views + dependencies: { } + 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, 20, 40, 60' + 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 + provider: views + dependencies: { } + style: + type: default + options: + grouping: { } + row_class: '' + default_row_class: true + uses_fields: false + provider: views + dependencies: { } + row: + type: fields + options: + inline: { } + separator: '' + hide_empty: false + default_field_elements: true + provider: views + dependencies: { } + fields: + name: + id: name + table: taxonomy_term_field_data + field: name + relationship: none + group_type: group + admin_label: '' + dependencies: + module: + - taxonomy + label: Name + exclude: false + alter: + alter_text: false + text: '' + 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: '' + 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: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + link_to_taxonomy: true + convert_spaces: false + plugin_id: taxonomy + provider: taxonomy + filters: { } + sorts: + tid: + id: tid + table: taxonomy_term_data + field: tid + relationship: none + group_type: group + admin_label: '' + dependencies: + module: + - views + order: ASC + exposed: false + expose: + label: '' + plugin_id: standard + provider: views + header: { } + footer: { } + empty: { } + relationships: { } + arguments: { } + field_langcode: '***CURRENT_LANGUAGE***' + field_langcode_add_to_query: null