ajax_render() uses array_merge_recursive() to merge the JS settings, as opposed to drupal_array_merge_deep_array() used in drupal_get_js(). When a module (mistakenly?) adds the same settings object twice or more (seen in Openlayers), ajax_render() fails to merge duplicate values for the same keys, producing arrays instead. This is different from drupal_get_js(), which correctly merges duplicate values into one.
The attached patch fixes the issue.
| Comment | File | Size | Author |
|---|---|---|---|
| ajax_render_js_settings_merging.patch | 611 bytes | jamix |
Comments
Comment #1
wim leersRelated issue in D8, where this behavior was changed: #1875632: JS settings merging behavior: preserve integer keys (allow for array literals in drupalSettings). Change notice: http://drupal.org/node/1911578.
Comment #2
jamix commentedComment #3
fabianx commentedRTBC, looks good to me.
Merging should be consistent.
Comment #5
jamix commentedLooks like this is no longer valid as both
drupal_get_js()andajax_render()usedrupal_array_merge_deep_array()now.Comment #6
fabianx commentedI think this is fixed then :). Please re-open if that is not the case! :)
Comment #7
lotyrin commentedThis is still an issue in 7. drupal_get_js() calls drupal_array_merge_deep_array() where ajax_render calls array_merge_recursive();
Comment #8
lotyrin commented#2153173: Loading media (via WYSIWYG) through AJAX causes duplicate settings values is a symptom of this.
Comment #9
lotyrin commentedNevermind, #208611: Add drupal_array_merge_deep() and drupal_array_merge_deep_array() to stop drupal_add_js() from adding settings twice solved this for 7.
Comment #12
David_Rothstein commented