Commit aa15f0ca authored by webchick's avatar webchick

Issue #2161727 by jrockowitz, damiankloip, dawehner: Views that use fields...

Issue #2161727 by jrockowitz, damiankloip, dawehner: Views that use fields with long names (ie 32 characters) will throw a show-stopping error.
parent fe9fcb17
......@@ -154,13 +154,13 @@ protected function getRoute($view_id, $display_id) {
if ($bit == '%') {
// Generate the name of the parameter using the key of the argument
// handler.
$arg_id = 'arg_' . $argument_ids[$arg_counter++];
$arg_id = 'arg_' . $arg_counter++;
$bits[$pos] = '{' . $arg_id . '}';
}
elseif (strpos($bit, '%') === 0) {
// Use the name defined in the path.
$parameter_name = substr($bit, 1);
$arg_id = 'arg_' . $argument_ids[$arg_counter++];
$arg_id = 'arg_' . $arg_counter++;
$argument_map[$arg_id] = $parameter_name;
$bits[$pos] = '{' . $parameter_name . '}';
}
......@@ -168,7 +168,7 @@ protected function getRoute($view_id, $display_id) {
// Add missing arguments not defined in the path, but added as handler.
while (($total_arguments - $arg_counter) > 0) {
$arg_id = 'arg_' . $argument_ids[$arg_counter++];
$arg_id = 'arg_' . $arg_counter++;
$bit = '{' . $arg_id . '}';
// In contrast to the previous loop add the defaults here, as % was not
// specified, which means the argument is optional.
......@@ -256,8 +256,8 @@ public function alterRoutes(RouteCollection $collection) {
// We assume that the numeric ids of the parameters match the one from
// the view argument handlers.
foreach ($parameters as $position => $parameter_name) {
$path = str_replace('arg_' . $argument_ids[$position], $parameter_name, $path);
$argument_map['arg_' . $argument_ids[$position]] = $parameter_name;
$path = str_replace('arg_' . $position, $parameter_name, $path);
$argument_map['arg_' . $position] = $parameter_name;
}
// Set the corrected path and the mapping to the route object.
$route->setDefault('_view_argument_map', $argument_map);
......
......@@ -75,13 +75,13 @@ public function handle(Request $request) {
$args = array();
$map = $request->attributes->get('_view_argument_map', array());
foreach (array_keys((array) $view->argument) as $argument_id) {
$arguments_length = count($view->argument);
for ($argument_index = 0; $argument_index < $arguments_length; $argument_index++) {
// Allow parameters be pulled from the request.
// The map stores the actual name of the parameter in the request. Views
// which override existing controller, use for example 'node' instead of
// arg_nid as name.
$attribute = 'arg_' . $argument_id;
$attribute = 'arg_' . $argument_index;
if (isset($map[$attribute])) {
$attribute = $map[$attribute];
......
......@@ -112,27 +112,27 @@ public function testPageRouterItems() {
$this->assertEqual($route->getPath(), '/test_route_without_arguments');
$route = $collection->get('view.test_page_display_route.page_2');
$this->assertEqual($route->getPath(), '/test_route_with_argument/{arg_id}');
$this->assertTrue($route->hasDefault('arg_id'), 'A default value is set for the optional argument id.');
$this->assertEqual($route->getPath(), '/test_route_with_argument/{arg_0}');
$this->assertTrue($route->hasDefault('arg_0'), 'A default value is set for the optional argument id.');
$route = $collection->get('view.test_page_display_route.page_3');
$this->assertEqual($route->getPath(), '/test_route_with_argument/{arg_id}/suffix');
$this->assertFalse($route->hasDefault('arg_id'), 'No default value is set for the required argument id.');
$this->assertEqual($route->getPath(), '/test_route_with_argument/{arg_0}/suffix');
$this->assertFalse($route->hasDefault('arg_0'), 'No default value is set for the required argument id.');
$route = $collection->get('view.test_page_display_route.page_4');
$this->assertEqual($route->getPath(), '/test_route_with_argument/{arg_id}/suffix/{arg_id_2}');
$this->assertFalse($route->hasDefault('arg_id'), 'No default value is set for the required argument id.');
$this->assertTrue($route->hasDefault('arg_id_2'), 'A default value is set for the optional argument id_2.');
$this->assertEqual($route->getPath(), '/test_route_with_argument/{arg_0}/suffix/{arg_1}');
$this->assertFalse($route->hasDefault('arg_0'), 'No default value is set for the required argument id.');
$this->assertTrue($route->hasDefault('arg_1'), 'A default value is set for the optional argument id_2.');
$route = $collection->get('view.test_page_display_route.page_5');
$this->assertEqual($route->getPath(), '/test_route_with_argument/{arg_id}/{arg_id_2}');
$this->assertTrue($route->hasDefault('arg_id'), 'A default value is set for the optional argument id.');
$this->assertTrue($route->hasDefault('arg_id_2'), 'A default value is set for the optional argument id_2.');
$this->assertEqual($route->getPath(), '/test_route_with_argument/{arg_0}/{arg_1}');
$this->assertTrue($route->hasDefault('arg_0'), 'A default value is set for the optional argument id.');
$this->assertTrue($route->hasDefault('arg_1'), 'A default value is set for the optional argument id_2.');
$route = $collection->get('view.test_page_display_route.page_6');
$this->assertEqual($route->getPath(), '/test_route_with_argument/{arg_id}/{arg_id_2}');
$this->assertFalse($route->hasDefault('arg_id'), 'No default value is set for the required argument id.');
$this->assertFalse($route->hasDefault('arg_id_2'), 'No default value is set for the required argument id_2.');
$this->assertEqual($route->getPath(), '/test_route_with_argument/{arg_0}/{arg_1}');
$this->assertFalse($route->hasDefault('arg_0'), 'No default value is set for the required argument id.');
$this->assertFalse($route->hasDefault('arg_1'), 'No default value is set for the required argument id_2.');
}
}
......@@ -67,6 +67,12 @@ public function testArguments() {
$result = $this->xpath('//span[@class="field-content"]');
$this->assertEqual(count($result), 1, 'Ensure that just the filtered entry was returned.');
$this->assertEqual((string) $result[0], 1, 'The passed ID was returned.');
$this->drupalGet('test_route_with_long_argument/1');
$this->assertResponse(200);
$result = $this->xpath('//span[@class="field-content"]');
$this->assertEqual(count($result), 1, 'Ensure that just the filtered entry was returned.');
$this->assertEqual((string) $result[0], 1, 'The passed ID was returned.');
}
/**
......
......@@ -212,7 +212,7 @@ public function testCollectRoutesWithNamedParameters() {
$this->assertEquals('/test_route/{node}/example', $route->getPath());
$this->assertEquals('test_id', $route->getDefault('view_id'));
$this->assertEquals('page_1', $route->getDefault('display_id'));
$this->assertEquals(array('arg_nid' => 'node'), $route->getDefault('_view_argument_map'));
$this->assertEquals(array('arg_0' => 'node'), $route->getDefault('_view_argument_map'));
}
/**
......@@ -248,7 +248,7 @@ public function testAlterRoutesWithParameters() {
$this->assertEquals('page_1', $route->getDefault('display_id'));
// Ensure that the path did not changed and placeholders are respected.
$this->assertEquals('/test_route/{parameter}', $route->getPath());
$this->assertEquals(array('arg_test_id' => 'parameter'), $route->getDefault('_view_argument_map'));
$this->assertEquals(array('arg_0' => 'parameter'), $route->getDefault('_view_argument_map'));
}
/**
......
......@@ -140,7 +140,7 @@ public function testHandleWithArgumentsWithoutOverridden() {
$request->attributes->set('view_id', 'test_page_view');
$request->attributes->set('display_id', 'page_1');
// Add the argument to the request.
$request->attributes->set('arg_test_id', 'test-argument');
$request->attributes->set('arg_0', 'test-argument');
$this->pageController->handle($request);
}
......@@ -188,7 +188,7 @@ public function testHandleWithArgumentsOnOveriddenRoute() {
// Add the argument to the request.
$request->attributes->set('parameter', 'test-argument');
$request->attributes->set('_view_argument_map', array(
'arg_test_id' => 'parameter',
'arg_0' => 'parameter',
));
$this->pageController->handle($request);
......@@ -241,7 +241,7 @@ public function testHandleWithArgumentsOnOveriddenRouteWithUpcasting() {
$request->attributes->set('_raw_variables', $raw_variables);
$request->attributes->set('_view_argument_map', array(
'arg_test_id' => 'test_entity',
'arg_0' => 'test_entity',
));
$this->pageController->handle($request);
......
......@@ -87,6 +87,23 @@ display:
display_title: Page
id: page_4
position: '0'
page_5:
display_options:
defaults:
arguments: '0'
arguments:
id_that_is_really_really_really_long:
field: id
id: id_that_is_really_really_really_long
relationship: none
table: views_test_data
plugin_id: numeric
provider: views_test_data
path: test_route_with_long_argument/%
display_plugin: page
display_title: Page
id: page_5
position: '0'
label: ''
id: test_page_display_arguments
tag: ''
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