Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
5738f39c
Commit
5738f39c
authored
Nov 26, 2014
by
Nathaniel Catchpole
Browse files
Issue
#2358603
by Berdir: ViewsAjaxController results in fatal error for empty optional arguments
parent
0bfb32b5
Changes
2
Hide whitespace changes
Inline
Side-by-side
core/modules/views/src/Controller/ViewAjaxController.php
View file @
5738f39c
...
...
@@ -79,6 +79,13 @@ public function ajaxView(Request $request) {
if
(
isset
(
$name
)
&&
isset
(
$display_id
))
{
$args
=
$request
->
request
->
get
(
'view_args'
);
$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'
);
$dom_id
=
$request
->
request
->
get
(
'view_dom_id'
);
$dom_id
=
isset
(
$dom_id
)
?
preg_replace
(
'/[^a-zA-Z0-9_-]+/'
,
'-'
,
$dom_id
)
:
NULL
;
...
...
@@ -130,8 +137,9 @@ public function ajaxView(Request $request) {
// Reuse the same DOM id so it matches that in drupalSettings.
$view
->
dom_id
=
$dom_id
;
$preview
=
$view
->
preview
(
$display_id
,
$args
);
$response
->
addCommand
(
new
ReplaceCommand
(
".view-dom-id-
$dom_id
"
,
$this
->
drupalRender
(
$preview
)));
if
(
$preview
=
$view
->
preview
(
$display_id
,
$args
))
{
$response
->
addCommand
(
new
ReplaceCommand
(
".view-dom-id-
$dom_id
"
,
$this
->
drupalRender
(
$preview
)));
}
return
$response
;
}
else
{
...
...
core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php
View file @
5738f39c
...
...
@@ -166,6 +166,27 @@ public function testAjaxViewWithArguments() {
$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.
*/
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment