Issue #1941288 by larowlan, effulgentsia, dawehner, nod_: Fixed Regression: ajaxPageState not being updated with AjaxResponse, assets (js/css) being added twice.
parent
1a0616faa1
commit
66178e047a
|
@ -2300,10 +2300,13 @@ function drupal_js_defaults($data = NULL) {
|
|||
* @param $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.
|
||||
* @param bool $is_ajax
|
||||
* (optional) If set to TRUE, this function is called from an Ajax request and
|
||||
* adds javascript settings to update ajaxPageState values.
|
||||
*
|
||||
* @return
|
||||
* All JavaScript code segments and includes for the scope as HTML tags.
|
||||
|
@ -2312,7 +2315,7 @@ function drupal_js_defaults($data = NULL) {
|
|||
* @see locale_js_alter()
|
||||
* @see drupal_js_defaults()
|
||||
*/
|
||||
function drupal_get_js($scope = 'header', $javascript = NULL, $skip_alter = FALSE) {
|
||||
function drupal_get_js($scope = 'header', $javascript = NULL, $skip_alter = FALSE, $is_ajax = FALSE) {
|
||||
if (!isset($javascript)) {
|
||||
$javascript = drupal_add_js();
|
||||
}
|
||||
|
@ -2338,12 +2341,7 @@ function drupal_get_js($scope = 'header', $javascript = NULL, $skip_alter = FALS
|
|||
uasort($items, 'drupal_sort_css_js');
|
||||
// Don't add settings if there is no other JavaScript on the page, unless
|
||||
// this is an AJAX request.
|
||||
// @todo Clean up container call.
|
||||
$container = drupal_container();
|
||||
if ($container->has('content_negotiation') && $container->isScopeActive('request')) {
|
||||
$type = $container->get('content_negotiation')->getContentType($container->get('request'));
|
||||
}
|
||||
if (!empty($items['settings']) || (!empty($type) && $type == 'ajax')) {
|
||||
if (!empty($items['settings']) || $is_ajax) {
|
||||
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.
|
||||
|
|
|
@ -111,8 +111,8 @@ class AjaxResponse extends JsonResponse {
|
|||
unset($items['js']['settings']);
|
||||
}
|
||||
$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);
|
||||
$scripts_footer = drupal_get_js('footer', $items['js'], TRUE, TRUE);
|
||||
$scripts_header = drupal_get_js('header', $items['js'], TRUE, TRUE);
|
||||
|
||||
// Prepend commands to add the resources, preserving their relative order.
|
||||
$resource_commands = array();
|
||||
|
|
|
@ -169,8 +169,7 @@ class FrameworkTest extends AjaxTestBase {
|
|||
|
||||
// Verify the expected CSS file was added, both to drupalSettings, and as
|
||||
// the second AJAX command for inclusion into the HTML.
|
||||
// @todo Uncomment this assertion after fixing http://drupal.org/node/1941288.
|
||||
//$this->assertEqual($new_css, $original_css + array($expected_css_basename => 1), format_string('Page state now has the %css file.', array('%css' => $expected['css'])));
|
||||
$this->assertEqual($new_css, $original_css + array($expected_css_basename => 1), format_string('Page state now has the %css file.', array('%css' => $expected['css'])));
|
||||
$this->assertCommand(array_slice($commands, 1, 1), array('data' => $expected_css_html), format_string('Page now has the %css file.', array('%css' => $expected['css'])));
|
||||
|
||||
// Verify the expected JS file was added, both to drupalSettings, and as
|
||||
|
@ -179,8 +178,7 @@ class FrameworkTest extends AjaxTestBase {
|
|||
// unexpected JavaScript code, such as a jQuery.extend() that would
|
||||
// potentially clobber rather than properly merge settings, didn't
|
||||
// accidentally get added.
|
||||
// @todo Uncomment this assertion after fixing http://drupal.org/node/1941288.
|
||||
//$this->assertEqual($new_js, $original_js + array($expected['js'] => 1), format_string('Page state now has the %js file.', array('%js' => $expected['js'])));
|
||||
$this->assertEqual($new_js, $original_js + array($expected['js'] => 1), format_string('Page state now has the %js file.', array('%js' => $expected['js'])));
|
||||
$this->assertCommand(array_slice($commands, 2, 1), array('data' => $expected_js_html), format_string('Page now has the %js file.', array('%js' => $expected['js'])));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue