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.
As I found out, reacting on new messages via Rules is very limited.
I can catch the event "privatemsg_insert" when a new PM is created. I need to delete the entity in certain situations, but that doesn't work. The message is sent as is. Changing PM values (subject, body, author, recipien) doesn't seem to work, either. But it would be okay for me to just cancel the message.
Maybe I just didn't find out how to use this feature. If so, some documentation would be greatly appreciated!
Comments
Comment #1
ptmkenny CreditAttribution: ptmkenny commentedIn which situations do you need to delete the entity? One possibility is structuring your rules with components so that private messages are only created when necessary.
There's a patch here that may also be of use:
https://drupal.org/node/1387740
Comment #2
Anonymous (not verified) CreditAttribution: Anonymous commentedIt's quite common to use callbacks for modifying or canceling the object in question. I can neither modify nor cancel the new message. Thus it's still a bug for my understanding, because this callback is so surprisingly incomplete. Beyond that it lacks any documentation. Deleting the entity fails without further notice.
My usecase is a keyword based abuse blocker. Not really a spam blocker, but a user promoting competing products shall not reach my audience. Currently the Rule disables the user's account and send an alert to the admin via email. The malicious message is delivered anyway, so the damage done.
I'll go the hook_privatemsg_message_validate() way, but the time for all this is lost.
I make it a feature request, as no support required.
Comment #3
BerdirThe insert hook/event is, like all other insert/update hooks/events, invoked *after* the messages was stored, so changing it does not have any effect.
The available hooks are documented on http://api.worldempire.ch/api/privatemsg/privatemsg.api.php/group/messag....
Comment #4
Anonymous (not verified) CreditAttribution: Anonymous commentedOkay, that's internal stuff and (from a Rules user's perspective) unexpected, as other events can modify entities. There is still one question that comes to mind:
If the message is already stored, how comes deleting the message entity fails? My assumption was the entity is about to be created (yet not persistent) and thus I can't delete it via Rules. But if it's already a stored entity, shouldn't I be able to delete it?
Comment #5
ivnish CreditAttribution: ivnish commented