diff --git a/includes/ajax.inc b/includes/ajax.inc index ab0111c..2d2d369 100644 --- a/includes/ajax.inc +++ b/includes/ajax.inc @@ -247,6 +247,10 @@ function ajax_render($commands = array()) { $function = 'drupal_add_' . $type; $items[$type] = $function(); drupal_alter($type, $items[$type]); + // If (altered) JS settings available, save them for later usage. + if (!empty($items['js']['settings'])) { + $js_settings = $items['js']['settings']; + } // @todo Inline CSS and JS items are indexed numerically. These can't be // reliably diffed with array_diff_key(), since the number can change // due to factors unrelated to the inline content, so for now, we strip @@ -288,11 +292,18 @@ function ajax_render($commands = array()) { $commands = array_merge($extra_commands, $commands); } + if (!isset($js_settings)) { + // We skipped altering above, do it here. + $scripts = drupal_add_js(); + drupal_alter('js', $scripts); + if (!empty($scripts['settings'])) { + $js_settings = $scripts['settings']; + } + } + // Now add a command to merge changes and additions to Drupal.settings. - $scripts = drupal_add_js(); - if (!empty($scripts['settings'])) { - $settings = $scripts['settings']; - array_unshift($commands, ajax_command_settings(call_user_func_array('array_merge_recursive', $settings['data']), TRUE)); + if (isset($js_settings)) { + array_unshift($commands, ajax_command_settings(call_user_func_array('array_merge_recursive', $js_settings['data']), TRUE)); } // Allow modules to alter any Ajax response.