I got a JavaScript error when trying to remove an image - some debugging traced the problem to onUserExit, which couldn't split options.internalURLs, because the value was missing:
Drupal.settings.content_lock.internal_urls
The DB table "variable" has a handful of settings, which correspond (e.g. DB field name "content_lock_unload_js_message" corresponds to JS variable "Drupal.settings.content_lock.unload_js_message".
I updated using Drush, and can find no reference to creating the setting "internal_urls" within the latest 1.3 code
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | content_lock-1525784.patch | 1.41 KB | ohnobinki |
| #5 | content_lock_split.patch | 584 bytes | liam morland |
Comments
Comment #1
ohnobinki commentedWhat does the
jQuery.extend(Drupal.settings, …);line look like in the HTML on that page? What URI were you accessing when this happened?The code in
onUserExit.jsonly gets initialized whencontent_lock_init.jsis added to a page. Whenevercontent_lock_init.jsis loaded on a page, it should be impossible forDrupal.settings.content_lock.internal_urlsto be unset.I cannot reproduce the problem, please provide details on how to reproduce this bug.
Comment #2
ClaudeS-1 commentedThis is the URL I'm on
admin#overlay=node/627/edit%3Fdestination%3Dadmin/content/node
It's just the standard edit page for a node.
This error occurs when I try to remove an image from an image field:
Here is the relevant part of jQuery.extend(Drupal.settings, …);
Using firebug, I can see that there is an object internalURLs which is an array with 2 items:
["node/627/edit", "node/627/edit"]Has the internalURLs variable changed from a pipe-separated string to an array in the latest release? I've cleared all caches in case the problem is stale JS, but it didn't help.
Comment #3
intu.cz commentedI confirm I also have the same problem, preventing me from adding more values to a field with multiple values.
The same message appears in Firebug:
connected with the file sites/all/modules/content_lock/js/onUserExit.js?m2dqkl line 111.
Comment #4
ohnobinki commentedOK, I'm able to reproduce it.
I think it has to do with how Drupal updates the Drupal.settings javascript variable with new data from AJAX requests, such as those it makes when uploading an image to an image field.
Comment #5
liam morlandI have been working on this for some time and have not found anything in core which would cause this problem. However, the attached patch fixes the problem by patching content_lock_init.js.
Comment #6
liam morlandComment #7
vurt commentedThe version 6.x-2.8 is also affected (6.x-2.6 is still working).
The patch (#5) fixes the problem for 6.x-2.8
Comment #8
mpotter commentedThis also fixed the issue in 7.x-1.3 for us. Without this patch a lot of ajax stuff was broken (removing images, adding new items to multivalue fields, etc). This patch really needs to be committed.
Comment #9
mikefyfer commentedAlso fixed in 7.x-1.3 for me. Hope the patch gets committed. thanks!
Comment #10
julien.reulos commentedHi,
No matter if I apply the patch or not, with the module activated I am not able to add a new item to a multivalue field of textareas anymore. the bug only occurs when I check "Use javascript to detect leaving the node form".
Firebug for Firefox debugging:
Firebug for Chromium debugging:
Line 26 of content_lock_init.js has this:
Comment #11
liam morland@#10 That looks like a different problem and should have its own issue.
Comment #12
julien.reulos commentedYep, sorry, testing with a fresh Drupal 7.14 instalation, I could check that Content Lock and this patch are working well. It seems that my problem is related to a incompatibility between jQuery Update module and CKeditor module.
Comment #13
ohnobinki commentedThe error is in file.module line 286 where array_merge_recursive() is used instead of drupal_array_merge_deep_array(). The latter function is the standard Drupal way of performing JavaScript Drupal.settings serialization; it is used in drupal_pre_render_scripts() (for D7 this code is in drupal_get_js()). When drupal_array_merge_deep_array() merges arrays, it replaces existing settings with more recently-added settings. In contrast, array_merge_recursive() will create an array containing both the original setting's value and the newer definitions.
Now that we know why this bug is experienced for the file field and not for a normal page load, we can better look at seeing the limitations in content_lock.module and possible workarounds. Somehow, there are two settings for
Drupal.settings.content_lock.internal_urls; this means that content_lock called drupal_add_js() with the same argument twice. Adding code into _content_lock_add_unload_js() to avoid calling drupal_add_js() a second time results in fixing the particular error discussed in this bug. Also, after some more debugging, it appears that _content_lock_add_unload_js() is only called twice for the AJAX image upload -- not on a normal page load. It does make sense to avoid such redundant calls to drupal_add_js(), so I think I'll add a workaround which protects against that. But the core bug (to be filed/found) does need fixing and I should do some investigation into why _content_lock_add_unload_js() is being called multiple when it is on a form that is being submitted.Comment #14
ohnobinki commentedComment #15
ohnobinki commentedThere is a fix in #1356170: Remove all uses of array_merge_recursive, or document why they are being used instead of NestedArray::mergeDeep(), please help get that patch through.
Comment #16
ohnobinki commentedThe workaround was committed to the 6.x-2.x branch after being made drupal-6 compatible at 7faf1b2. Releases with this fix for all versions coming "soon" ;-).
Comment #17
ohnobinki commentedFixed in 6.x-2.9 and 7.x-1.4.
Sorry for taking so long on this. Don't forget to help get the core issue, #1356170: Remove all uses of array_merge_recursive, or document why they are being used instead of NestedArray::mergeDeep(), fixed.
Comment #19
mrconnerton commented@ohnobinki can you clarify if this should be working on it's own in 7.x-1.4 or if a backport patch from #1356170: Remove all uses of array_merge_recursive, or document why they are being used instead of NestedArray::mergeDeep() is required?
edit: Version changed on it's own btw