Problem/Motivation
We add some additional fields to the node form that we put in the existing node author details element.
Normal users don't have access to change the owner/author of a node.
The nodeDetailsSummaries behavior assumes that the uid field is always visible if the wrapping details element is. In our case, that assumption is wrong.
What happens then is that name is undefined, is passed to Drupal.t(), down to formatString() and that does checkPlain(undefined), and that causes an error.
Proposed resolution
I'm not sure if this is the correct fix, but explicitly checking in Drupal.formatString() if args[key] doesn't just exist but is not undefined solves the actual JS problem. but maybe that behavior should also care about this and don't display a broken string then in that case?
Also, fun side node. seven never shows those summaries, but we still spend time on every request to calculate them them...
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#22 | 2535220-do-not-test.patch | 544 bytes | David_Rothstein |
#17 | 2535220-17.patch | 976 bytes | Sivaji_Ganesh_Jojodae |
#12 | 2535220-12.patch | 934 bytes | mbaynton |
#5 | 2535220-node-summary-error.patch | 932 bytes | droplet |
#1 | 2535220-javascript-format-string-null-1.patch | 461 bytes | Berdir |
Comments
Comment #1
BerdirComment #2
droplet CreditAttribution: droplet commentedFirefox only?
`checkPlain(undefined)`, personally I don't think we need to handle this case, let's see what's nod_ thought.
Comment #3
BerdirComment #4
BerdirTo reproduce:
* admin/structure/types/manage/article/form-display, move "authored by" to hidden
* Then go to node/add/article
Yes, we've only seen it on Firefox. The problem it self should happen on Chrome as well, but for some reason, chrome never executed the problematic part:
I tried adding a breakpoint inside that function but it was never triggered. Might be completely broken in Chrome but it's not visible in Seven.
Comment #5
droplet CreditAttribution: droplet commentedChrome has native Detail tag supports that will not trigger CollapsibleDetails.setupSummary().
Comment #6
BerdirFixing the actual problem definitely makes sense, but I think it might still be a good idea to prevent javascript errors due to incorrect custom/contrib code?
Comment #7
droplet CreditAttribution: droplet commentedI think we should address them in 2 different issues.
Improve in Drupal.checkPlain needed further discussion.
Comment #8
droplet CreditAttribution: droplet commentedComment #9
stockholmz CreditAttribution: stockholmz as a volunteer commented#1 This will definitely fix this issue of not trying to handle undefined. Alternatively, to be absolutely sure you could consider checking if its a string also.
#5 This is a way better solution for the isolated bug. Although I would consider checking if undefined, rather than just bool-checking. (Unsure whether this is a code-standard thing). - Tested and confirmed to remove the error.
Comment #11
droplet CreditAttribution: droplet commentedif statement in JS also checking `undefined` and `null`.
Comment #12
mbayntonreroll #5
Comment #13
mbayntonI think this solution, #12 in particular is ready to RTBC, however wrt. #7, I agree that also checkPlain should itself guard against this to increase robustness of page's overall JS.
My reroll is just an automerge of #5; I took no actual part in authoring anything so consider myself a legit RTBC-er.
Comment #14
alexpottCommitted da0789a and pushed to 8.0.x and 8.1.x. Thanks!
Comment #17
Sivaji_Ganesh_Jojodae CreditAttribution: Sivaji_Ganesh_Jojodae commentedPatch for D7.
Comment #19
droplet CreditAttribution: droplet commentedComment #20
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedWhat is the bug here in Drupal 7? How is it reproducible?
The node.js file is added via this code:
And then in JavaScript (as visible in the patch context):
So how could "name" ever wind up undefined?
Comment #21
BerdirJust like in D8, it's not without altering the form.
If you put custom form elements/fields into the author fieldset but the user doesn't have access to the name field, then you get this.
Comment #22
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedI tried that before leaving my comment - what I used to deny access to the field was the code in the attached patch. And I didn't get a JavaScript error, for the reasons mentioned above.
Now I guess there is a bug in that scenario since the summary says "By anonymous" (even though the node isn't being created by the anonymous user)! But the patch in this issue won't fix that.
Comment #23
BerdirYou're right. D8 doesn't have the anonymous fallback.
I think that was removed because we switched to the default entity reference widget which uses an explicit reference for the anonymous user unlike D7. (which was then changed again and apparently this part was never changed back. But I dislike that change anyway and that's a different topic.
Anyway, you're right, I guess we can close this. Or we need an explicit check to see if the field exists and not just if it has a value or not. Because the current patch doesn't make sense.
Setting to needs work for that, but if you think that's not important enough, feel free to close it.
Comment #26
stefan.r CreditAttribution: stefan.r commented