diff --git a/core/includes/common.inc b/core/includes/common.inc index 9f3f373..54c77c7 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -3796,13 +3796,13 @@ function drupal_js_defaults($data = NULL) { * is to add another element to the $javascript array, deriving from * drupal_js_defaults(). See locale_js_alter() for an example of this. * - * @param $scope + * @param string $scope * (optional) The scope for which the JavaScript rules should be returned. * Defaults to 'header'. - * @param $javascript + * @param array $javascript * (optional) An array with all JavaScript code. Defaults to the default * JavaScript array for the given scope. - * @param $skip_alter + * @param bool $skip_alter * (optional) If set to TRUE, this function skips calling drupal_alter() on * $javascript, useful when the calling function passes a $javascript array * that has already been altered. @@ -3845,7 +3845,6 @@ function drupal_get_js($scope = 'header', $javascript = NULL, $skip_alter = FALS // a later AJAX request can be rendered using the same theme. // @see ajax_base_page_theme() $setting['ajaxPageState']['theme'] = $theme_key; - error_log('js ahoy'); // Checks that the DB is available before filling theme_token. if (!defined('MAINTENANCE_MODE')) { $setting['ajaxPageState']['theme_token'] = drupal_get_token($theme_key); diff --git a/core/lib/Drupal/Core/Ajax/AjaxResponse.php b/core/lib/Drupal/Core/Ajax/AjaxResponse.php index ccd7ce3..2d3cbe1 100644 --- a/core/lib/Drupal/Core/Ajax/AjaxResponse.php +++ b/core/lib/Drupal/Core/Ajax/AjaxResponse.php @@ -27,7 +27,7 @@ class AjaxResponse extends JsonResponse { * * @param object $command * An AJAX command object implementing CommandInterface. - * @param boolean $prepend + * @param bool $prepend * A boolean which determines whether the new command should be executed * before previously added commands. Defaults to FALSE. * @@ -111,9 +111,6 @@ protected function ajaxRender(Request $request) { unset($items['js']['settings']); } - // Make sure that drupal_get_js() returns settings by injecting an empty - // setting. - $items['js']['settings'] = array('data' => array(), 'scope' => 'header'); $styles = drupal_get_css($items['css'], TRUE); $scripts_footer = drupal_get_js('footer', $items['js'], TRUE); $scripts_header = drupal_get_js('header', $items['js'], TRUE); @@ -137,6 +134,36 @@ protected function ajaxRender(Request $request) { $scripts = drupal_add_js(); if (!empty($scripts['settings'])) { $settings = drupal_merge_js_settings($scripts['settings']['data']); + // Setup ajaxPageState. + global $theme_key; + // Provide the page with information about the theme that's used, so that + // a later AJAX request can be rendered using the same theme. + // @see ajax_base_page_theme() + $settings['ajaxPageState']['theme'] = $theme_key; + // Checks that the DB is available before filling theme_token. + if (!defined('MAINTENANCE_MODE')) { + $settings['ajaxPageState']['theme_token'] = drupal_get_token($theme_key); + } + + // Provide the page with information about the individual JavaScript files + // used, information not otherwise available when aggregation is enabled. + $settings['ajaxPageState']['js'] = array_fill_keys(array_keys($scripts), 1); + unset($settings['ajaxPageState']['js']['settings']); + + // Provide the page with information about the individual CSS files used, + // information not otherwise available when CSS aggregation is enabled. + // The setting is attached later in this function, but is set here, so + // that CSS files removed in drupal_process_attached() are still + // considered "used" and prevented from being added in a later AJAX + // request. + // Skip if no files were added to the page otherwise jQuery.extend() will + // overwrite the Drupal.settings.ajaxPageState.css object with an empty + // array. + $css = drupal_add_css(); + if (!empty($css)) { + // Cast the array to an object to be on the safe side even if not empty. + $settings['ajaxPageState']['css'] = (object) array_fill_keys(array_keys($css), 1); + } $this->addCommand(new SettingsCommand($settings, TRUE), TRUE); } diff --git a/core/modules/system/lib/Drupal/system/Tests/Ajax/DialogTest.php b/core/modules/system/lib/Drupal/system/Tests/Ajax/DialogTest.php index 32aea71..29c8bfb 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Ajax/DialogTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Ajax/DialogTest.php @@ -35,7 +35,7 @@ function testDialog() { 'settings' => NULL, 'data' => $dialog_contents, 'dialogOptions' => array( - 'modal' => true, + 'modal' => TRUE, 'title' => 'AJAX Dialog', ), ); @@ -45,7 +45,7 @@ function testDialog() { 'settings' => NULL, 'data' => $dialog_contents, 'dialogOptions' => array( - 'modal' => false, + 'modal' => FALSE, 'title' => 'AJAX Dialog', ), ); 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 219bb44..1ec42e5 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Ajax/FrameworkTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Ajax/FrameworkTest.php @@ -52,6 +52,7 @@ function testOrder() { $expected_commands[1] = new AddCssCommand(drupal_get_css(drupal_add_css(), TRUE)); drupal_static_reset('drupal_add_js'); drupal_add_js($path . '/system.js'); + $expected_commands[2] = new PrependCommand('head', drupal_get_js('header', drupal_add_js(), TRUE)); drupal_static_reset('drupal_add_js'); drupal_add_js($path . '/system.modules.js', array('scope' => 'footer'));