Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
If we have code such as:
function commons_trusted_contacts_privatemsg_message_validate($message, $form = FALSE) {
global $_privatemsg_invalid_recipients;
$_privatemsg_invalid_recipients = array();
$errors = array();
foreach ($message->recipients as $recipient) {
if (!commons_group_is_trusted_contact($recipient->name)) {
$_privatemsg_invalid_recipients[] = $recipient->uid;
if ($form) {
dpm("form true");
$errors[] = form_set_error('recipient', 'test');
return $errors;
}
else {
dpm("form not true");
$errors[] = t('You cannot message %name because this person is not a trusted contact of yours.', array('%name' => privatemsg_recipient_format($recipient, array('plain' => TRUE))));
return $errors;
}
}
}
}
and $form is true, then both form_set_error() and privatemsg.module will print the text passed to form_set_error(), resulting in a duplicate message.
As an alternative, I can use an empty string for my form_set_error() text and do my own drupal_set_message(). However, if I'm going to use my own drupal_set_mesasge(), then I'm not using Privatemsg's dsm() anyway.
I suggest not printing these messages on behalf of developers.
Comment | File | Size | Author |
---|---|---|---|
#1 | 2038179-1-privatemsg-duplicate-messages.patch | 490 bytes | ezra-g |
Comments
Comment #1
ezra-g CreditAttribution: ezra-g commentedAs proposed in the OP.
Comment #2
ptmkenny CreditAttribution: ptmkenny commentedComment #3
ptmkenny CreditAttribution: ptmkenny commented#1: 2038179-1-privatemsg-duplicate-messages.patch queued for re-testing.
Comment #4
ivnish CreditAttribution: ivnish commented