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.
An event for "user is blocked" in Rules would be fantastic. I think that user being blocked is a pretty important event in a community, and being able to execute an action when this happens would open the door to some very useful and intuitive functionality.
Comments
Comment #1
BerdirOk, a few hints...
- privatemsg_rules needs something to act on, so we need to add a hook when a user is blocked/unblocked. This needs to be added to the function http://blog.worldempire.ch/de/api/function/pm_block_user_form_submit/6-2. We want probably want to pass the action (block/unblock), the $recipient that blocks someone and the $author.
This will look something like this:
- Next, that hook also needs documentation. Create pm_block_user.api.php (similiar to privatemsg.api.php) and document that hook there, similiar to the hooks in privatemsg.api.php This is not important for a first step (it works fine without but is needed to.. well, have documentation ;))
- Then, we need to define the event in privatemsg_rules.rules.inc, see http://blog.worldempire.ch/de/api/function/privatemsg_rules_rules_event_.... I guess you could actually make two events, one when a user is blocked and one when he is unblocked. Copy the whole privatemsg_insert part, add it twice, give it a name (instead of privatemsg_insert), label and remove all arguments except author and recipient
- Then implement the hook we've created before by creating a function called privatemsg_rules_pm_block_user_blocked($action, $recipient, $author). Add a if ($action == 'block_user') { // trigger block event here } else { // trigger unblock event here). See http://blog.worldempire.ch/de/api/function/privatemsg_rules_privatemsg_m... on how to trigger an event.
Just start somewhere, implement what you can and upload it (if possible, as a patch, see http://drupal.org/patch/create). I'll try to answer any questions. You can also join the #drupal-games IRC channel, then I can help directly if I'm there.
(Only 6.x-2.x-dev has rules integration and gets new features added..)
Comment #2
mark. CreditAttribution: mark. commentedI've been swamped with work at my job and haven't had the time to get going on this, but I just wanted to quickly thank you for taking the time to post all of this info.
My next post will be some actual code. Thanks again!
Comment #3
ptmkenny CreditAttribution: ptmkenny commentedGreetings,
I'm also a PHP novice but having the ability to act on blocked users would really help my site so I decided to give this a shot.
I'm using Drupal 7 and it appears the code has changed significantly.
I added the hook to pm_block_user_form_submit. Then I copied the privatemsg_insert part and modified the arguments.
However, I'm lost about how to actually trigger the event. I tried searching the file but I couldn't figure out how the triggers are implemented in D7 rules. Any pointers would be much appreciated.
Comment #4
mark. CreditAttribution: mark. commentedComment #5
ivnish CreditAttribution: ivnish commented