Issue #2358603 by Berdir: ViewsAjaxController results in fatal error for empty optional arguments
parent
0bfb32b55b
commit
5738f39ccd
|
@ -79,6 +79,13 @@ class ViewAjaxController implements ContainerInjectionInterface {
|
||||||
if (isset($name) && isset($display_id)) {
|
if (isset($name) && isset($display_id)) {
|
||||||
$args = $request->request->get('view_args');
|
$args = $request->request->get('view_args');
|
||||||
$args = isset($args) && $args !== '' ? explode('/', $args) : array();
|
$args = isset($args) && $args !== '' ? explode('/', $args) : array();
|
||||||
|
|
||||||
|
// Arguments can be empty, make sure they are passed on as NULL so that
|
||||||
|
// argument validation is not triggered.
|
||||||
|
$args = array_map(function ($arg) {
|
||||||
|
return ($arg == '' ? NULL : $arg);
|
||||||
|
}, $args);
|
||||||
|
|
||||||
$path = $request->request->get('view_path');
|
$path = $request->request->get('view_path');
|
||||||
$dom_id = $request->request->get('view_dom_id');
|
$dom_id = $request->request->get('view_dom_id');
|
||||||
$dom_id = isset($dom_id) ? preg_replace('/[^a-zA-Z0-9_-]+/', '-', $dom_id) : NULL;
|
$dom_id = isset($dom_id) ? preg_replace('/[^a-zA-Z0-9_-]+/', '-', $dom_id) : NULL;
|
||||||
|
@ -130,8 +137,9 @@ class ViewAjaxController implements ContainerInjectionInterface {
|
||||||
// Reuse the same DOM id so it matches that in drupalSettings.
|
// Reuse the same DOM id so it matches that in drupalSettings.
|
||||||
$view->dom_id = $dom_id;
|
$view->dom_id = $dom_id;
|
||||||
|
|
||||||
$preview = $view->preview($display_id, $args);
|
if ($preview = $view->preview($display_id, $args)) {
|
||||||
$response->addCommand(new ReplaceCommand(".view-dom-id-$dom_id", $this->drupalRender($preview)));
|
$response->addCommand(new ReplaceCommand(".view-dom-id-$dom_id", $this->drupalRender($preview)));
|
||||||
|
}
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -166,6 +166,27 @@ class ViewAjaxControllerTest extends UnitTestCase {
|
||||||
$this->assertViewResultCommand($response);
|
$this->assertViewResultCommand($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests a valid view with arguments.
|
||||||
|
*/
|
||||||
|
public function testAjaxViewWithEmptyArguments() {
|
||||||
|
$request = new Request();
|
||||||
|
$request->request->set('view_name', 'test_view');
|
||||||
|
$request->request->set('view_display_id', 'page_1');
|
||||||
|
// Simulate a request that has a second, empty argument.
|
||||||
|
$request->request->set('view_args', 'arg1/');
|
||||||
|
|
||||||
|
list($view, $executable) = $this->setupValidMocks();
|
||||||
|
$executable->expects($this->once())
|
||||||
|
->method('preview')
|
||||||
|
->with('page_1', $this->identicalTo(array('arg1', NULL)));
|
||||||
|
|
||||||
|
$response = $this->viewAjaxController->ajaxView($request);
|
||||||
|
$this->assertTrue($response instanceof ViewAjaxResponse);
|
||||||
|
|
||||||
|
$this->assertViewResultCommand($response);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests a valid view with a pager.
|
* Tests a valid view with a pager.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue