Skip to content
Snippets Groups Projects
Unverified Commit 0946a51c authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2710407 by bobbygryzynger, dww, Kingdutch, Krzysztof Domański,...

Issue #2710407 by bobbygryzynger, dww, Kingdutch, Krzysztof Domański, jp.stacey, johnny5th, tea.time, joachim, andileco, Lendude, xjm, percoction: Option for 'Transform dashes in URL to spaces in term name filter values' on term arguments doesn't affect the query

(cherry picked from commit 75d67d4c)
parent 145d174f
No related branches found
No related tags found
No related merge requests found
......@@ -64,6 +64,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
public function validateArgument($argument) {
if ($this->options['transform']) {
$argument = str_replace('-', ' ', $argument);
$this->argument->argument = $argument;
}
$terms = $this->termStorage->loadByProperties(['name' => $argument]);
......
<?php
namespace Drupal\Tests\taxonomy\Kernel\Views;
use Drupal\views\Views;
/**
* Tests taxonomy term argument transformation.
*
* @group taxonomy
*
* @see \Drupal\taxonomy\Plugin\views\argument_validator\TermName
*/
class ArgumentTransformTermTest extends TaxonomyTestBase {
/**
* {@inheritdoc}
*/
public static $testViews = ['test_argument_transform_term'];
/**
* Tests term argument transformation of hyphens and spaces.
*
* @dataProvider termArgumentTransformationProvider
*
* @param string $name
* The name of the taxonomy term to use for the test.
*/
public function testTermArgumentTransformation($name) {
/** @var \Drupal\taxonomy\TermInterface $term */
$term = $this->createTerm(['name' => $name]);
/** @var \Drupal\views\ViewExecutable $view */
$view = Views::getView('test_argument_transform_term');
$view->initHandlers();
/** @var string $hyphenated_term */
$hyphenated_term = str_replace(' ', '-', $term->label());
$this->assertTrue($view->argument['tid']->setArgument($hyphenated_term));
// Assert hyphens are converted back to spaces.
$this->assertEquals($term->label(), $view->argument['tid']->argument);
}
/**
* Provides data for testTermArgumentTransformation().
*
* @return array[]
* Test data.
*/
public function termArgumentTransformationProvider() {
return [
'space in the middle' => [
'name' => $this->randomMachineName() . ' ' . $this->randomMachineName(),
],
'space at the start' => [
'name' => ' ' . $this->randomMachineName(),
],
'space at the end' => [
'name' => $this->randomMachineName() . ' ',
],
];
}
}
langcode: en
status: true
dependencies:
module:
- node
- taxonomy
- user
id: test_argument_transform_term
label: test_argument_transform_term
module: views
description: ''
tag: ''
base_table: node_field_data
base_field: nid
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:
title:
id: title
table: node_field_data
field: title
entity_type: node
entity_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
settings:
link_to_entity: true
plugin_id: field
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
click_sort_column: value
type: string
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
filters:
status:
value: '1'
table: node_field_data
field: status
plugin_id: boolean
entity_type: node
entity_field: status
id: status
expose:
operator: ''
operator_limit_selection: false
operator_list: { }
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
header: { }
footer: { }
empty: { }
relationships: { }
arguments:
tid:
id: tid
table: taxonomy_index
field: tid
relationship: none
group_type: group
admin_label: ''
default_action: ignore
exception:
value: all
title_enable: false
title: All
title_enable: true
title: '{{ raw_arguments.tid }}'
default_argument_type: fixed
default_argument_options:
argument: ''
default_argument_skip_url: false
summary_options:
base_path: ''
count: true
items_per_page: 25
override: false
summary:
sort_order: asc
number_of_records: 0
format: default_summary
specify_validation: true
validate:
type: taxonomy_term_name
fail: 'not found'
validate_options:
operation: view
transform: true
bundles: { }
access: false
break_phrase: false
add_table: false
require_value: false
reduce_duplicates: false
plugin_id: taxonomy_index_tid
display_extenders: { }
cache_metadata:
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url
- url.query_args
- 'user.node_grants:view'
- user.permissions
cacheable: false
max-age: -1
tags: { }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment