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.

Files: 
CommentFileSizeAuthor
#1 2038179-1-privatemsg-duplicate-messages.patch490 bytesezra-g
PASSED: [[SimpleTest]]: [MySQL] 4,913 pass(es). View

Comments

ezra-g’s picture

Title:using form_set_error() in hook_privatemsg_message_validate() implementations results in duplicate messages» using form_set_error() in hook_privatemsg_message_validate() implementations results in duplicate validation messages
Status:Active» Needs review
FileSize
490 bytes
PASSED: [[SimpleTest]]: [MySQL] 4,913 pass(es). View

As proposed in the OP.

ptmkenny’s picture

Version:7.x-1.x-dev» 7.x-2.x-dev
ptmkenny’s picture