Updated: Comment #0
Problem/Motivation
It is possible to change javascript settings via hook_js_alter(), but the settings are returned unaltered from ajax request.
For example:
function mymodule_js_alter(&$javascript) {
$javascript['settings']['data'][1]['pathPrefix'] = 'whatever/';
}
Proposed resolution
Use the altered JS settings - if they are available.
Remaining tasks
* Create proper patch.
Patch:
diff --git a/docroot/includes/ajax.inc b/docroot/includes/ajax.inc
index ab0111c..dc0491e 100644
--- a/docroot/includes/ajax.inc
+++ b/docroot/includes/ajax.inc
@@ -267,7 +267,10 @@ function ajax_render($commands = array()) {
// HTML in the page. We pass TRUE as the $skip_alter argument to prevent the
// data from being altered again, as we already altered it above. Settings are
// handled separately, afterwards.
+
+ $scripts = array();
if (isset($items['js']['settings'])) {
+ $scripts['settings'] = $items['js']['settings'];
unset($items['js']['settings']);
}
$styles = drupal_get_css($items['css'], TRUE);
@@ -289,7 +292,10 @@ function ajax_render($commands = array()) {
}
// Now add a command to merge changes and additions to Drupal.settings.
- $scripts = drupal_add_js();
+ // Only reload the settings when its not yet set.
+ if (!isset($scripts['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));