Commit bfdcc65a authored by xjm's avatar xjm
Browse files

Issue #2459777 by jibran, Jaesin, tstoeckler, TR: {taxonomy_index} and...

Issue #2459777 by jibran, Jaesin, tstoeckler, TR: {taxonomy_index} and {taxonomy_term_hierarchy} doesn't join taxonomy data table in views
parent 79e74a27
......@@ -141,8 +141,8 @@ public function getViewsData() {
$data['taxonomy_index']['table']['group'] = t('Taxonomy term');
$data['taxonomy_index']['table']['join'] = array(
'taxonomy_term_data' => array(
// links directly to taxonomy_term_data via tid
'taxonomy_term_field_data' => array(
// links directly to taxonomy_term_field_data via tid
'left_field' => 'tid',
'field' => 'tid',
),
......@@ -169,8 +169,8 @@ public function getViewsData() {
),
);
// @todo This stuff needs to move to a node field since really it's all about
// nodes.
// @todo This stuff needs to move to a node field since really it's all
// about nodes.
$data['taxonomy_index']['tid'] = array(
'group' => t('Content'),
'title' => t('Has taxonomy term ID'),
......@@ -229,6 +229,7 @@ public function getViewsData() {
];
$data['taxonomy_term_hierarchy']['table']['group'] = t('Taxonomy term');
$data['taxonomy_term_hierarchy']['table']['provider'] = 'taxonomy';
$data['taxonomy_term_hierarchy']['table']['join'] = array(
'taxonomy_term_hierarchy' => array(
......@@ -236,8 +237,8 @@ public function getViewsData() {
'left_field' => 'tid',
'field' => 'parent',
),
'taxonomy_term_data' => array(
// Link directly to taxonomy_term_data via tid.
'taxonomy_term_field_data' => array(
// Link directly to taxonomy_term_field_data via tid.
'left_field' => 'tid',
'field' => 'tid',
),
......@@ -247,7 +248,7 @@ public function getViewsData() {
'title' => t('Parent term'),
'help' => t('The parent term of the term. This can produce duplicate entries if you are using a vocabulary that allows multiple parents.'),
'relationship' => array(
'base' => 'taxonomy_term_data',
'base' => 'taxonomy_term_field_data',
'field' => 'parent',
'label' => t('Parent'),
'id' => 'standard',
......
<?php
/**
* @file
* Contains \Drupal\taxonomy\Tests\Views\TaxonomyParentUITest.
*/
namespace Drupal\taxonomy\Tests\Views;
use Drupal\node\NodeInterface;
use Drupal\taxonomy\TermInterface;
use Drupal\views\Tests\ViewTestData;
use Drupal\views\Views;
/**
* Tests taxonomy relationships with parent term and node.
*
* @group taxonomy
*/
class TaxonomyRelationshipTest extends TaxonomyTestBase {
/**
* Stores the terms used in the tests.
*
* @var \Drupal\taxonomy\TermInterface[]
*/
protected $terms = array();
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_taxonomy_term_relationship');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Make term2 parent of term1.
$this->term1->set('parent', $this->term2->id());
$this->term1->save();
// Store terms in an array for testing.
$this->terms[] = $this->term1;
$this->terms[] = $this->term2;
// Only set term1 on node1 and term2 on node2 for testing.
unset($this->nodes[0]->field_views_testing_tags[1]);
$this->nodes[0]->save();
unset($this->nodes[1]->field_views_testing_tags[0]);
$this->nodes[1]->save();
Views::viewsData()->clear();
}
/**
* Tests the taxonomy parent plugin UI.
*/
public function testTaxonomyRelationships() {
// Check the generated views data of taxonomy_index.
$views_data = Views::viewsData()->get('taxonomy_index');
// Check the table join data.
$this->assertEqual($views_data['table']['join']['taxonomy_term_field_data']['left_field'], 'tid');
$this->assertEqual($views_data['table']['join']['taxonomy_term_field_data']['field'], 'tid');
$this->assertEqual($views_data['table']['join']['node_field_data']['left_field'], 'nid');
$this->assertEqual($views_data['table']['join']['node_field_data']['field'], 'nid');
$this->assertEqual($views_data['table']['join']['taxonomy_term_hierarchy']['left_field'], 'tid');
$this->assertEqual($views_data['table']['join']['taxonomy_term_hierarchy']['field'], 'tid');
// Check the generated views data of taxonomy_term_hierarchy.
$views_data = Views::viewsData()->get('taxonomy_term_hierarchy');
// Check the table join data.
$this->assertEqual($views_data['table']['join']['taxonomy_term_hierarchy']['left_field'], 'tid');
$this->assertEqual($views_data['table']['join']['taxonomy_term_hierarchy']['field'], 'parent');
$this->assertEqual($views_data['table']['join']['taxonomy_term_field_data']['left_field'], 'tid');
$this->assertEqual($views_data['table']['join']['taxonomy_term_field_data']['field'], 'tid');
// Check the parent relationship data.
$this->assertEqual($views_data['parent']['relationship']['base'], 'taxonomy_term_field_data');
$this->assertEqual($views_data['parent']['relationship']['field'], 'parent');
$this->assertEqual($views_data['parent']['relationship']['label'], t('Parent'));
$this->assertEqual($views_data['parent']['relationship']['id'], 'standard');
// Check the parent filter and argument data.
$this->assertEqual($views_data['parent']['filter']['id'], 'numeric');
$this->assertEqual($views_data['parent']['argument']['id'], 'taxonomy');
// Check an actual test view.
$view = Views::getView('test_taxonomy_term_relationship');
$this->executeView($view);
/** @var \Drupal\views\ResultRow $row */
foreach ($view->result as $index => $row) {
// Check that the actual ID of the entity is the expected one.
$this->assertEqual($row->tid, $this->terms[$index]->id());
// Also check that we have the correct result entity.
$this->assertEqual($row->_entity->id(), $this->terms[$index]->id());
$this->assertTrue($row->_entity instanceof TermInterface);
if (!$index) {
$this->assertTrue($row->_relationship_entities['parent'] instanceof TermInterface);
$this->assertEqual($row->_relationship_entities['parent']->id(), $this->term2->id());
$this->assertEqual($row->taxonomy_term_field_data_taxonomy_term_hierarchy_tid, $this->term2->id());
}
$this->assertTrue($row->_relationship_entities['nid'] instanceof NodeInterface);
$this->assertEqual($row->_relationship_entities['nid']->id(), $this->nodes[$index]->id());
}
}
}
langcode: en
status: true
dependencies:
module:
- node
- taxonomy
- user
id: test_taxonomy_term_relationship
label: test_taxonomy_term_relationship
module: views
description: ''
tag: ''
base_table: taxonomy_term_field_data
base_field: tid
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: none
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:
tid:
id: tid
table: taxonomy_term_field_data
field: tid
entity_type: taxonomy_term
entity_field: tid
plugin_id: field
tid_1:
id: tid_1
table: taxonomy_term_field_data
field: tid
relationship: parent
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
click_sort_column: value
type: number_integer
settings:
thousand_separator: ''
prefix_suffix: true
group_column: value
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
entity_type: taxonomy_term
entity_field: tid
plugin_id: field
nid:
id: nid
table: node
field: nid
entity_type: node
entity_field: nid
plugin_id: field
relationship: nid
filters: { }
sorts:
tid:
id: tid
table: taxonomy_term_field_data
field: tid
entity_type: taxonomy_term
entity_field: tid
plugin_id: standard
header: { }
footer: { }
empty: { }
relationships:
nid:
id: nid
table: taxonomy_index
field: nid
relationship: none
group_type: group
admin_label: node
required: false
plugin_id: standard
parent:
id: parent
table: taxonomy_term_hierarchy
field: parent
relationship: none
group_type: group
admin_label: Parent
required: false
plugin_id: standard
arguments: { }
display_extenders: { }
cache_metadata:
contexts:
- 'languages:language_content'
- 'languages:language_interface'
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