Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
drupal
Commits
7ed96147
Commit
7ed96147
authored
Aug 18, 2013
by
catch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#1691394
by pwolanin, nod_, tim.plunkett: Fixed Drupal settings gets broken by AJAX requests.
parent
75644c15
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
5 deletions
+33
-5
core/lib/Drupal/Core/Ajax/AjaxResponse.php
core/lib/Drupal/Core/Ajax/AjaxResponse.php
+9
-0
core/modules/system/lib/Drupal/system/Tests/Ajax/FrameworkTest.php
...les/system/lib/Drupal/system/Tests/Ajax/FrameworkTest.php
+17
-5
core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module
...stem/tests/modules/ajax_forms_test/ajax_forms_test.module
+7
-0
No files found.
core/lib/Drupal/Core/Ajax/AjaxResponse.php
View file @
7ed96147
...
...
@@ -133,6 +133,15 @@ protected function ajaxRender(Request $request) {
$scripts
=
drupal_add_js
();
if
(
!
empty
(
$scripts
[
'settings'
]))
{
$settings
=
drupal_merge_js_settings
(
$scripts
[
'settings'
][
'data'
]);
// During Ajax requests basic path-specific settings are excluded from
// new drupalSettings values. The original page where this request comes
// from already has the right values for the keys below. An Ajax request
// would update them with values for the Ajax request and incorrectly
// override the page's values.
// @see drupal_add_js
foreach
(
array
(
'basePath'
,
'currentPath'
,
'scriptPath'
,
'pathPrefix'
)
as
$item
)
{
unset
(
$settings
[
$item
]);
}
$this
->
addCommand
(
new
SettingsCommand
(
$settings
,
TRUE
),
TRUE
);
}
...
...
core/modules/system/lib/Drupal/system/Tests/Ajax/FrameworkTest.php
View file @
7ed96147
...
...
@@ -29,7 +29,7 @@ public static function getInfo() {
/**
* Ensures ajax_render() returns JavaScript settings from the page request.
*/
function
testAJAXRender
()
{
public
function
testAJAXRender
()
{
// Verify that settings command is generated when JavaScript settings are
// set via drupal_add_js().
$commands
=
$this
->
drupalGetAJAX
(
'ajax-test/render'
);
...
...
@@ -40,7 +40,7 @@ function testAJAXRender() {
/**
* Tests AjaxResponse::prepare() AJAX commands ordering.
*/
function
testOrder
()
{
public
function
testOrder
()
{
$path
=
drupal_get_path
(
'module'
,
'system'
);
$expected_commands
=
array
();
...
...
@@ -82,7 +82,7 @@ function testOrder() {
/**
* Tests behavior of ajax_render_error().
*/
function
testAJAXRenderError
()
{
public
function
testAJAXRenderError
()
{
// Verify custom error message.
$edit
=
array
(
'message'
=>
'Custom error message.'
,
...
...
@@ -95,7 +95,7 @@ function testAJAXRenderError() {
/**
* Tests that new JavaScript and CSS files are lazy-loaded on an AJAX request.
*/
function
testLazyLoad
()
{
public
function
testLazyLoad
()
{
$expected
=
array
(
'setting_name'
=>
'ajax_forms_test_lazy_load_form_submit'
,
'setting_value'
=>
'executed'
,
...
...
@@ -182,10 +182,22 @@ function testLazyLoad() {
$this
->
assertCommand
(
array_slice
(
$commands
,
2
,
1
),
array
(
'data'
=>
$expected_js_html
),
format_string
(
'Page now has the %js file.'
,
array
(
'%js'
=>
$expected
[
'js'
])));
}
/**
* Tests that drupalSettings.currentPath is not updated on AJAX requests.
*/
public
function
testCurrentPathChange
()
{
$commands
=
$this
->
drupalPostAJAX
(
'ajax_forms_test_lazy_load_form'
,
array
(
'add_files'
=>
FALSE
),
array
(
'op'
=>
t
(
'Submit'
)));
foreach
(
$commands
as
$command
)
{
if
(
$command
[
'command'
]
==
'settings'
)
{
$this
->
assertFalse
(
isset
(
$command
[
'settings'
][
'currentPath'
]),
'Value of drupalSettings.currentPath is not updated after an AJAX request.'
);
}
}
}
/**
* Tests that overridden CSS files are not added during lazy load.
*/
function
testLazyLoadOverriddenCSS
()
{
public
function
testLazyLoadOverriddenCSS
()
{
// The test theme overrides system.module.css without an implementation,
// thereby removing it.
theme_enable
(
array
(
'test_theme'
));
...
...
core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module
View file @
7ed96147
...
...
@@ -534,6 +534,13 @@ function ajax_forms_test_validation_number_form_callback($form, $form_state) {
* Form builder: Builds a form that triggers a simple AJAX callback.
*/
function
ajax_forms_test_lazy_load_form
(
$form
,
&
$form_state
)
{
// We attach a JavaScript setting, so that one of the generated AJAX commands
// will be a settings command. We can then check the settings command to
// ensure that the 'currentPath' setting is not part of the Ajax response.
$form
[
'#attached'
][
'js'
][]
=
array
(
'type'
=>
'setting'
,
'data'
=>
array
(
'test'
=>
'currentPathUpdate'
),
);
$form
[
'add_files'
]
=
array
(
'#type'
=>
'checkbox'
,
'#default_value'
=>
FALSE
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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