This patch removes the longstanding issue with drupal_add_js()'s use of array_merge_recursive() which prevent uc_option_images from working when more than one node was displayed at a time. Working around this issue required several tricks:

  • Access DOM elements that are children of the context returned by Drupal Behaviors (for the form elements), or access them by unique ID (for the image block div)
  • Abandon the use of a global 'nodeid' settings attribute in favour of a hidden form value containing the node ID, added by a form_alter hook
  • Use $prep to ensure that the global settings are only ever added/merged on the first call
  • Use a string array index for the node IDs of $data['images'] so that array_merge_recursive() doesn't append the numerical keys, which is what would cause the bizarre and duplicated JS setting arrays

Note that this patch builds on/requires the Drupal Behaviors patch posted in comment #43 of #712542: Compatibility with Ubercart Ajax Attribute Calculations module.


stewart.adam’s picture

stewart.adam’s picture

I realized that after uploading this that I had missed a small mistake in the code that generates the ID for the image block div that would result in invalid XHTML or multiple divs with the same ID at times - this one works correctly.