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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
fd846046
Commit
fd846046
authored
12 years ago
by
Angie Byron
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#1812866
follow-up by mkadin, effulgentsia, Wim Leers: Fixed Rebuild the...
Issue
#1812866
follow-up by mkadin, effulgentsia, Wim Leers: Fixed Rebuild the server side AJAX API.
parent
4433a2a2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
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
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/lib/Drupal/Core/Ajax/AjaxResponse.php
+28
-13
28 additions, 13 deletions
core/lib/Drupal/Core/Ajax/AjaxResponse.php
with
28 additions
and
13 deletions
core/lib/Drupal/Core/Ajax/AjaxResponse.php
+
28
−
13
View file @
fd846046
...
...
@@ -27,20 +27,29 @@ class AjaxResponse extends JsonResponse {
*
* @param object $command
* An AJAX command object implementing CommandInterface.
* @param boolean $prepend
* A boolean which determines whether the new command should be executed
* before previously added commands. Defaults to FALSE.
*
* @return AjaxResponse
* The current AjaxResponse.
*/
public
function
addCommand
(
$command
)
{
$this
->
commands
[]
=
$command
->
render
();
public
function
addCommand
(
$command
,
$prepend
=
FALSE
)
{
if
(
$prepend
)
{
array_unshift
(
$this
->
commands
,
$command
->
render
());
}
else
{
$this
->
commands
[]
=
$command
->
render
();
}
return
$this
;
}
/**
* Sets the response's data to be the array of AJAX commands.
*
* @param
*
$request
A request object.
* @param
Request $request
* A request object.
*
* @return
* Response The current response.
...
...
@@ -54,24 +63,25 @@ public function prepare(Request $request) {
/**
* Prepares the AJAX commands for sending back to the client.
*
* @param Request
* @param Request
$request
* The request object that the AJAX is responding to.
*
* @return array
* An array of commands ready to be returned as JSON.
*/
protected
function
ajaxRender
(
$request
)
{
protected
function
ajaxRender
(
Request
$request
)
{
// Ajax responses aren't rendered with html.tpl.php, so we have to call
// drupal_get_css() and drupal_get_js() here, in order to have new files
// added during this request to be loaded by the page. We only want to send
// back files that the page hasn't already loaded, so we implement simple
// diffing logic using array_diff_key().
$ajax_page_state
=
$request
->
request
->
get
(
'ajax_page_state'
);
foreach
(
array
(
'css'
,
'js'
)
as
$type
)
{
// It is highly suspicious if $_POST['ajax_page_state'][$type] is empty,
// since the base page ought to have at least one JS file and one CSS file
// loaded. It probably indicates an error, and rather than making the page
// reload all of the files, instead we return no new files.
if
(
empty
(
$
request
->
parameters
[
'
ajax_page_state
'
]
[
$type
]))
{
if
(
empty
(
$ajax_page_state
[
$type
]))
{
$items
[
$type
]
=
array
();
}
else
{
...
...
@@ -90,7 +100,7 @@ protected function ajaxRender($request) {
}
}
// Ensure that the page doesn't reload what it already has.
$items
[
$type
]
=
array_diff_key
(
$items
[
$type
],
$
request
->
parameters
[
'
ajax_page_state
'
]
[
$type
]);
$items
[
$type
]
=
array_diff_key
(
$items
[
$type
],
$ajax_page_state
[
$type
]);
}
}
...
...
@@ -105,21 +115,26 @@ protected function ajaxRender($request) {
$scripts_footer
=
drupal_get_js
(
'footer'
,
$items
[
'js'
],
TRUE
);
$scripts_header
=
drupal_get_js
(
'header'
,
$items
[
'js'
],
TRUE
);
// Prepend commands to add the resources, preserving their relative order.
$resource_commands
=
array
();
if
(
!
empty
(
$styles
))
{
$
this
->
addCommand
(
new
AddCssCommand
(
$styles
)
)
;
$
resource_commands
[]
=
new
AddCssCommand
(
$styles
);
}
if
(
!
empty
(
$scripts_header
))
{
$
this
->
addCommand
(
new
PrependCommand
(
'head'
,
$scripts_header
)
)
;
$
resource_commands
[]
=
new
PrependCommand
(
'head'
,
$scripts_header
);
}
if
(
!
empty
(
$scripts_footer
))
{
$this
->
addCommand
(
new
AppendCommand
(
'body'
,
$scripts_footer
));
$resource_commands
[]
=
new
AppendCommand
(
'body'
,
$scripts_footer
);
}
foreach
(
array_reverse
(
$resource_commands
)
as
$resource_command
)
{
$this
->
addCommand
(
$resource_command
,
TRUE
);
}
//
Now ad
d a command to merge changes and additions to Drupal.settings.
//
Prepen
d a command to merge changes and additions to Drupal.settings.
$scripts
=
drupal_add_js
();
if
(
!
empty
(
$scripts
[
'settings'
]))
{
$settings
=
$scripts
[
'settings'
];
$this
->
addCommand
(
new
SettingsCommand
(
call_user_func_array
(
'array_merge_recursive'
,
$settings
[
'data'
]),
TRUE
));
$this
->
addCommand
(
new
SettingsCommand
(
call_user_func_array
(
'array_merge_recursive'
,
$settings
[
'data'
]),
TRUE
)
,
TRUE
);
}
$commands
=
$this
->
commands
;
...
...
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