Commit 82f9f8c5 authored by catch's avatar catch

Issue #2407853 by alexpott, aerozeppelin, Berdir, vladan.me, dawehner:...

Issue #2407853 by alexpott, aerozeppelin, Berdir, vladan.me, dawehner: TaxonomyIndexTid Views plugin stores selected terms with the ID instead of UUID
parent 9ec1f42d
......@@ -391,8 +391,7 @@ public function calculateDependencies() {
$vocabulary = $this->vocabularyStorage->load($this->options['vid']);
$dependencies[$vocabulary->getConfigDependencyKey()][] = $vocabulary->getConfigDependencyName();
foreach ($this->options['value'] as $tid) {
$term = $this->termStorage->load($tid);
foreach ($this->termStorage->loadMultiple($this->options['value']) as $term) {
$dependencies[$term->getConfigDependencyKey()][] = $term->getConfigDependencyName();
}
......
<?php
namespace Drupal\taxonomy\Tests\Views;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\views\Entity\View;
use Drupal\views\Tests\ViewTestData;
/**
* Test the taxonomy term index filter.
*
* @see \Drupal\taxonomy\Plugin\views\filter\TaxonomyIndexTid
*
* @group taxonomy
*/
class TaxonomyIndexTidFilterTest extends TaxonomyTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['taxonomy', 'taxonomy_test_views', 'views', 'node'];
/**
* {@inheritdoc}
*/
public static $testViews = ['test_filter_taxonomy_index_tid__non_existing_dependency'];
/**
* @var \Drupal\taxonomy\TermInterface[]
*/
protected $terms = [];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp(FALSE);
// Setup vocabulary and terms so the initial import is valid.
Vocabulary::create([
'vid' => 'tags',
'name' => 'Tags',
])->save();
// This will get a term ID of 3.
$term = Term::create([
'vid' => 'tags',
'name' => 'muh',
]);
$term->save();
// This will get a term ID of 4.
$this->terms[$term->id()] = $term;
$term = Term::create([
'vid' => 'tags',
'name' => 'muh',
]);
$term->save();
$this->terms[$term->id()] = $term;
ViewTestData::createTestViews(get_class($this), array('taxonomy_test_views'));
}
/**
* Tests dependencies are not added for terms that do not exist.
*/
public function testConfigDependency() {
/** @var \Drupal\views\Entity\View $view */
$view = View::load('test_filter_taxonomy_index_tid__non_existing_dependency');
// Dependencies are sorted.
$content_dependencies = [
$this->terms[3]->getConfigDependencyName(),
$this->terms[4]->getConfigDependencyName(),
];
sort($content_dependencies);
$this->assertEqual([
'config' => [
'taxonomy.vocabulary.tags',
],
'content' => $content_dependencies,
'module' => [
'node',
'taxonomy',
'user',
],
], $view->calculateDependencies()->getDependencies());
$this->terms[3]->delete();
$this->assertEqual([
'config' => [
'taxonomy.vocabulary.tags',
],
'content' => [
$this->terms[4]->getConfigDependencyName(),
],
'module' => [
'node',
'taxonomy',
'user',
],
], $view->calculateDependencies()->getDependencies());
}
/**
* Tests post update function fixes dependencies.
*
* @see views_post_update_taxonomy_index_tid()
*/
public function testPostUpdateFunction() {
/** @var \Drupal\views\Entity\View $view */
$view = View::load('test_filter_taxonomy_index_tid__non_existing_dependency');
// Dependencies are sorted.
$content_dependencies = [
$this->terms[3]->getConfigDependencyName(),
$this->terms[4]->getConfigDependencyName(),
];
sort($content_dependencies);
$this->assertEqual([
'config' => [
'taxonomy.vocabulary.tags',
],
'content' => $content_dependencies,
'module' => [
'node',
'taxonomy',
'user',
],
], $view->calculateDependencies()->getDependencies());
$this->terms[3]->delete();
\Drupal::moduleHandler()->loadInclude('views', 'post_update.php');
views_post_update_taxonomy_index_tid();
$view = View::load('test_filter_taxonomy_index_tid__non_existing_dependency');
$this->assertEqual([
'config' => [
'taxonomy.vocabulary.tags',
],
'content' => [
$this->terms[4]->getConfigDependencyName(),
],
'module' => [
'node',
'taxonomy',
'user',
],
], $view->getDependencies());
}
}
......@@ -55,11 +55,13 @@ abstract class TaxonomyTestBase extends ViewTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->mockStandardInstall();
ViewTestData::createTestViews(get_class($this), array('taxonomy_test_views'));
if ($import_test_views) {
ViewTestData::createTestViews(get_class($this), array('taxonomy_test_views'));
}
$this->term1 = $this->createTerm();
$this->term2 = $this->createTerm();
......
langcode: en
status: true
dependencies:
module:
- node
- taxonomy
- user
id: test_filter_taxonomy_index_tid__non_existing_dependency
label: test_filter_taxonomy_index_tid__non_existing_dependency
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: 1
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:
title:
id: title
table: node_field_data
field: title
label: ''
alter:
alter_text: false
make_link: false
absolute: false
trim: false
word_boundary: false
ellipsis: false
strip_tags: false
html: false
hide_empty: false
empty_zero: false
relationship: none
group_type: group
admin_label: ''
exclude: 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_alter_empty: true
plugin_id: field
entity_type: node
entity_field: title
filters:
status:
value: true
table: node_field_data
field: status
id: status
expose:
operator: '0'
group: 1
plugin_id: boolean
entity_type: node
entity_field: status
tid:
id: tid
table: taxonomy_index
field: tid
relationship: none
group_type: group
admin_label: ''
operator: or
value:
- 3
- 4
group: 1
exposed: false
expose:
operator_id: '0'
label: ''
description: ''
use_operator: false
operator: ''
identifier: ''
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
reduce: false
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
reduce_duplicates: false
type: select
limit: true
vid: tags
hierarchy: true
error_message: true
plugin_id: taxonomy_index_tid
sorts: { }
header: { }
footer: { }
empty: { }
relationships: { }
arguments: { }
page_1:
display_plugin: page
id: page_1
display_title: Page
position: 2
display_options:
display_extenders: { }
path: test-filter-taxonomy-index-tid
......@@ -159,3 +159,26 @@ function views_post_update_field_formatter_dependencies() {
/**
* @} End of "addtogroup updates-8.0.x".
*/
/**
* @addtogroup updates-8.1.x
* @{
*/
/**
* Fix views with dependencies on taxonomy terms that don't exist.
*/
function views_post_update_taxonomy_index_tid() {
$views = View::loadMultiple();
array_walk($views, function(View $view) {
$old_dependencies = $view->getDependencies();
$new_dependencies = $view->calculateDependencies()->getDependencies();
if ($old_dependencies !== $new_dependencies) {
$view->save();
}
});
}
/**
* @} End of "addtogroup updates-8.1.x".
*/
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