A not-yet-often seen bug (or at least visual ugliness). Every multistep form is built twice. Thus, where the form building process calls drupal_set_message() (such as the #after_build element in the node form) this will cause each message to display twice.
Two possible fixes:
1) for 5.x: the form-building code should save and then restore the messages for one of the two instances of form building.
2) for 6.x: every unique message gets a unique ID (an additional parameter to drupal_set_message), like the form ID, or mail ID in drupal_mail. Thus, setting the same message many times results in only one message being output.
Comments
Comment #1
pwolanin commentedOr, I just had a another idea- that might be good for 4.7.x forward: why not use the md5() of the message as the array key?
Comment #2
RobRoy commentedI feel like we should fix the underlying problem that is resulting in a double call instead of "fixing" dsm().
Comment #3
eaton commentedThis is relatively esoteric: drupal_set_message() is being called in an #after_build, which means that multistep forms pop up doubled messages. Really, we shouldn't be setting messages in forms at all: it causes weird display issues in Programmatically submitted forms, for example. That's why form_set_error() is used for logging errors, and *it* outputs drupal_set_message() calls when appropriate.
I'm not sure what the best short-term solution is, but I'll take a look at the patch.
Comment #4
chx commentedEven if decide that we want to unique every message, md5()'ing is totally unneeded, there is no size constrain on array keys. And arrays are hashes themselves, no need to manually hash.
Comment #5
pwolanin commentedIf I correctly grok what chx is suggesting, it would be:
I don't think it's actually that esoteric - I've seen problems with other modules that call drupal_set_message() in a place in the code that it may get called twice per page load. While I agree that this should be avoided, a simple change like this to insure each message only prints once seems like an easy one. Real patch to follow in a few hours.
Comment #6
pwolanin commentedpatch attached for 5.x. Tested and does result in multiple identical messages only being displayed once.
Comment #7
dries commentedThis is a feature, not a bug. The problem is not with drupal_set_message() but with the code calling drupal_set_message().
Comment #8
pwolanin commentedOk, if its a desired feature to show every message, then this isssue should just be about how to avoid the multiple calls to drupal_set_message(). I think the only way to do that is to eliminate the call to drupal_set_message as part of the #after_build step. Perhaps the message could just be generated as normal markup and pre-pended to the node preview?
Comment #9
RobRoy commented@pwolanin - That's correct. Switch any multistep dsm() calls to #prefix markup and you'll be fine. Is this set to 'active' for a reason? Does this problem exist in core somewhere?
Comment #10
pwolanin commentedYes, the problem exists in the node form-
<break>tag.Comment #11
tstoecklerThis is won't fix per #7. If #10 is still an issue, please open a new issue.