diff --git a/core/lib/Drupal/Core/Ajax/AjaxResponse.php b/core/lib/Drupal/Core/Ajax/AjaxResponse.php index 2a72267..b823288 100644 --- a/core/lib/Drupal/Core/Ajax/AjaxResponse.php +++ b/core/lib/Drupal/Core/Ajax/AjaxResponse.php @@ -133,6 +133,9 @@ protected function ajaxRender(Request $request) { $scripts = drupal_add_js(); if (!empty($scripts['settings'])) { $settings = drupal_merge_js_settings($scripts['settings']['data']); + foreach (array('basePath', 'currentPath', 'scriptPath', 'pathPrefix') as $item) { + unset($settings[$item]); + } $this->addCommand(new SettingsCommand($settings, TRUE), TRUE); } diff --git a/core/modules/system/lib/Drupal/system/Tests/Ajax/FrameworkTest.php b/core/modules/system/lib/Drupal/system/Tests/Ajax/FrameworkTest.php index e30b55c..998b27b 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Ajax/FrameworkTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Ajax/FrameworkTest.php @@ -185,6 +185,18 @@ function testLazyLoad() { } /** + * Tests that drupalSettings.currentPath is not updated on AJAX requests. + */ + 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() { diff --git a/core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module b/core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module index 67f5322..21e846b 100644 --- a/core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module +++ b/core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module @@ -534,6 +534,12 @@ 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) { + // Adds JS settings to check that upon loading the form with AJAX + // drupalSettings.currentPath value is not updated with the AJAX path. + $form['#attached']['js'][] = array( + 'type' => 'setting', + 'data' => array('test' => 'currentPathUpdate'), + ); $form['add_files'] = array( '#type' => 'checkbox', '#default_value' => FALSE,