Commit 7f6305a6 authored by alexpott's avatar alexpott

Issue #2507727 by mikeker, olli: Adding an "All taxonomy terms" field results...

Issue #2507727 by mikeker, olli: Adding an "All taxonomy terms" field results in "Invalid parameter number" error
parent 76ecf77f
......@@ -318,23 +318,24 @@ public function resetWeights($vid) {
/**
* {@inheritdoc}
*/
public function getNodeTerms($nids, $vocabs = array(), $langcode = NULL) {
public function getNodeTerms(array $nids, array $vocabs = array(), $langcode = NULL) {
$query = db_select('taxonomy_term_field_data', 'td');
$query->innerJoin('taxonomy_index', 'tn', 'td.tid = tn.tid');
$query->fields('td', array('tid'));
$query->addField('tn', 'nid', 'node_nid');
$query->orderby('td.weight');
$query->orderby('td.name');
$query->condition('tn.nid', $nids);
$query->condition('tn.nid', $nids, 'IN');
$query->addTag('term_access');
if (!empty($vocabs)) {
$query->condition('td.vid', $vocabs);
$query->condition('td.vid', $vocabs, 'IN');
}
if (!empty($langcode)) {
$query->condition('td.langcode', $langcode);
}
$results = array();
$all_tids = array();
foreach ($query->execute() as $term_record) {
$results[$term_record->node_nid][] = $term_record->tid;
$all_tids[] = $term_record->tid;
......@@ -344,7 +345,7 @@ public function getNodeTerms($nids, $vocabs = array(), $langcode = NULL) {
$terms = array();
foreach ($results as $nid => $tids) {
foreach ($tids as $tid) {
$terms[$nid][$tid] = $all_terms[$term_record->tid];
$terms[$nid][$tid] = $all_terms[$tid];
}
}
return $terms;
......
......@@ -121,6 +121,6 @@ public function resetWeights($vid);
* @return array
* An array of nids and the term entities they were tagged with.
*/
public function getNodeTerms($nids, $vocabs = array(), $langcode = NULL);
public function getNodeTerms(array $nids, array $vocabs = array(), $langcode = NULL);
}
<?php
/**
* @file
* Contains \Drupal\taxonomy\Tests\Views\TaxonomyFieldAllTerms.
*/
namespace Drupal\taxonomy\Tests\Views;
use Drupal\views\Views;
/**
* Tests the "All terms" taxonomy term field handler.
*
* @group taxonomy
*/
class TaxonomyFieldAllTermsTest extends TaxonomyTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('taxonomy_all_terms_test');
function testViewsHandlerAllTermsField() {
$view = Views::getView('taxonomy_all_terms_test');
$this->executeView($view);
$this->drupalGet('taxonomy_all_terms_test');
$actual = $this->xpath('//a[@href="' . $this->term1->url() . '"]');
$this->assertEqual(count($actual), 2, 'Correct number of taxonomy term1 links');
$this->assertEqual($actual[0]->__toString(), $this->term1->label());
$this->assertEqual($actual[1]->__toString(), $this->term1->label());
$actual = $this->xpath('//a[@href="' . $this->term2->url() . '"]');
$this->assertEqual(count($actual), 2, 'Correct number of taxonomy term2 links');
$this->assertEqual($actual[0]->__toString(), $this->term2->label());
$this->assertEqual($actual[1]->__toString(), $this->term2->label());
}
}
langcode: en
status: true
dependencies:
module:
- node
- taxonomy
- user
id: taxonomy_all_terms_test
label: taxonomy_all_terms_test
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
options:
grouping: { }
row_class: ''
default_row_class: true
uses_fields: false
row:
type: fields
options:
inline: { }
separator: ''
hide_empty: false
default_field_elements: true
fields:
term_node_tid:
id: term_node_tid
table: node_field_data
field: term_node_tid
relationship: none
group_type: group
admin_label: ''
label: ''
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: 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
type: separator
separator: ', '
link_to_taxonomy: true
limit: false
vids:
tags: '0'
entity_type: node
plugin_id: taxonomy_index_tid
filters: { }
sorts:
nid:
id: nid
table: node
field: nid
relationship: none
group_type: group
admin_label: ''
order: ASC
exposed: false
expose:
label: ''
entity_type: node
entity_field: nid
plugin_id: standard
header: { }
footer: { }
empty: { }
relationships: { }
arguments: { }
display_extenders: { }
cache_metadata:
contexts:
- 'languages:language_interface'
- 'url.query_args.pagers:0'
- 'user.node_grants:view'
- user.permissions
cacheable: false
page_1:
display_plugin: page
id: page_1
display_title: Page
position: 1
display_options:
display_extenders: { }
path: taxonomy_all_terms_test
cache_metadata:
contexts:
- 'languages:language_interface'
- 'url.query_args.pagers:0'
- 'user.node_grants:view'
- user.permissions
cacheable: false
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment