Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
b28f5b81
Commit
b28f5b81
authored
Nov 29, 2013
by
catch
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2071145
by dawehner: Regression: Allow to change the commands of an ajax response.
parent
1b5f414a
No related branches found
No related tags found
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/lib/Drupal/Core/Ajax/AjaxResponse.php
+12
-2
12 additions, 2 deletions
core/lib/Drupal/Core/Ajax/AjaxResponse.php
core/tests/Drupal/Tests/Core/Ajax/AjaxResponseTest.php
+81
-0
81 additions, 0 deletions
core/tests/Drupal/Tests/Core/Ajax/AjaxResponseTest.php
with
93 additions
and
2 deletions
core/lib/Drupal/Core/Ajax/AjaxResponse.php
+
12
−
2
View file @
b28f5b81
...
...
@@ -26,7 +26,7 @@ class AjaxResponse extends JsonResponse {
/**
* Add an AJAX command to the response.
*
* @param
object
$command
* @param
\Drupal\Core\Ajax\CommandInterface
$command
* An AJAX command object implementing CommandInterface.
* @param boolean $prepend
* A boolean which determines whether the new command should be executed
...
...
@@ -35,7 +35,7 @@ class AjaxResponse extends JsonResponse {
* @return AjaxResponse
* The current AjaxResponse.
*/
public
function
addCommand
(
$command
,
$prepend
=
FALSE
)
{
public
function
addCommand
(
CommandInterface
$command
,
$prepend
=
FALSE
)
{
if
(
$prepend
)
{
array_unshift
(
$this
->
commands
,
$command
->
render
());
}
...
...
@@ -46,6 +46,16 @@ public function addCommand($command, $prepend = FALSE) {
return
$this
;
}
/**
* Gets all AJAX commands.
*
* @return \Drupal\Core\Ajax\CommandInterface[]
* Returns all previously added AJAX commands.
*/
public
function
&
getCommands
()
{
return
$this
->
commands
;
}
/**
* {@inheritdoc}
*
...
...
This diff is collapsed.
Click to expand it.
core/tests/Drupal/Tests/Core/Ajax/AjaxResponseTest.php
0 → 100644
+
81
−
0
View file @
b28f5b81
<?php
/**
* @file
* Contains \Drupal\Tests\Core\Ajax\AjaxResponseTest.
*/
namespace
Drupal\Tests\Core\Ajax
;
use
Drupal\Core\Ajax\AjaxResponse
;
use
Drupal\Tests\UnitTestCase
;
/**
* Tests the AJAX response object.
*
* @see \Drupal\Core\Ajax\AjaxResponse
*/
class
AjaxResponseTest
extends
UnitTestCase
{
/**
* The tested ajax response object.
*
* @var \Drupal\Core\Ajax\AjaxResponse
*/
protected
$ajaxResponse
;
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'Ajax Response Object'
,
'description'
=>
'Tests the AJAX response object.'
,
'group'
=>
'Ajax'
,
);
}
protected
function
setUp
()
{
$this
->
ajaxResponse
=
new
AjaxResponse
();
}
/**
* Tests the add and getCommands method.
*
* @see \Drupal\Core\Ajax\AjaxResponse::addCommand()
* @see \Drupal\Core\Ajax\AjaxResponse::getCommands()
*/
public
function
testCommands
()
{
$command_one
=
$this
->
getMock
(
'Drupal\Core\Ajax\CommandInterface'
);
$command_one
->
expects
(
$this
->
once
())
->
method
(
'render'
)
->
will
(
$this
->
returnValue
(
array
(
'command'
=>
'one'
)));
$command_two
=
$this
->
getMock
(
'Drupal\Core\Ajax\CommandInterface'
);
$command_two
->
expects
(
$this
->
once
())
->
method
(
'render'
)
->
will
(
$this
->
returnValue
(
array
(
'command'
=>
'two'
)));
$command_three
=
$this
->
getMock
(
'Drupal\Core\Ajax\CommandInterface'
);
$command_three
->
expects
(
$this
->
once
())
->
method
(
'render'
)
->
will
(
$this
->
returnValue
(
array
(
'command'
=>
'three'
)));
$this
->
ajaxResponse
->
addCommand
(
$command_one
);
$this
->
ajaxResponse
->
addCommand
(
$command_two
);
$this
->
ajaxResponse
->
addCommand
(
$command_three
,
TRUE
);
// Ensure that the added commands are in the right order.
$commands
=&
$this
->
ajaxResponse
->
getCommands
();
$this
->
assertSame
(
$commands
[
1
],
array
(
'command'
=>
'one'
));
$this
->
assertSame
(
$commands
[
2
],
array
(
'command'
=>
'two'
));
$this
->
assertSame
(
$commands
[
0
],
array
(
'command'
=>
'three'
));
// Remove one and change one element from commands and ensure the reference
// worked as expected.
unset
(
$commands
[
2
]);
$commands
[
0
][
'class'
]
=
'test-class'
;
$commands
=
$this
->
ajaxResponse
->
getCommands
();
$this
->
assertSame
(
$commands
[
1
],
array
(
'command'
=>
'one'
));
$this
->
assertFalse
(
isset
(
$commands
[
2
]));
$this
->
assertSame
(
$commands
[
0
],
array
(
'command'
=>
'three'
,
'class'
=>
'test-class'
));
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment