Commit e12c6850 authored by alexpott's avatar alexpott

Issue #2804375 by Lendude, dawehner: Exception thrown when using [view:url]...

Issue #2804375 by Lendude, dawehner: Exception thrown when using [view:url] token when there is no display with a URL in the view
parent 03fba965
langcode: en
status: true
dependencies: { }
id: test_invalid_tokens
label: 'Test invalid tokens'
module: views
description: 'Test view to invalid token replacement tests.'
tag: ''
base_table: views_test_data
base_field: id
core: 8.x
display:
default:
display_options:
title: 'Test token default'
defaults:
fields: false
pager: false
sorts: false
fields:
age:
field: age
id: age
relationship: none
table: views_test_data
plugin_id: numeric
id:
field: id
id: id
relationship: none
table: views_test_data
plugin_id: numeric
name:
field: name
id: name
relationship: none
table: views_test_data
plugin_id: string
pager:
type: full
options:
items_per_page: 10
display_plugin: default
display_title: Master
id: default
position: 0
block_1:
display_plugin: block
id: block_1
display_title: Block
position: 1
display_options:
display_extenders: { }
......@@ -19,7 +19,7 @@ class TokenReplaceTest extends ViewsKernelTestBase {
*
* @var array
*/
public static $testViews = array('test_tokens');
public static $testViews = array('test_tokens', 'test_invalid_tokens');
protected function setUp($import_test_views = TRUE) {
parent::setUp();
......@@ -90,4 +90,23 @@ function testTokenReplacementNoResults() {
}
}
/**
* Tests path token replacements generated from a view without a path.
*/
function testTokenReplacementNoPath() {
$token_handler = \Drupal::token();
$view = Views::getView('test_invalid_tokens');
$view->setDisplay('block_1');
$this->executeView($view);
$expected = array(
'[view:url]' => '',
);
foreach ($expected as $token => $expected_output) {
$output = $token_handler->replace($token, array('view' => $view));
$this->assertIdentical($output, $expected_output, format_string('Token %token replaced correctly.', array('%token' => $token)));
}
}
}
......@@ -101,9 +101,15 @@ function views_tokens($type, $tokens, array $data, array $options, BubbleableMet
break;
case 'url':
if ($url = $view->getUrl()) {
$replacements[$original] = $url->setOptions($url_options)
->toString();
try {
if ($url = $view->getUrl()) {
$replacements[$original] = $url->setOptions($url_options)
->toString();
}
}
catch (\InvalidArgumentException $e) {
// The view has no URL so we leave the value empty.
$replacements[$original] = '';
}
break;
case 'base-table':
......
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