I am trying to create a simple block user functionality on my site. I have a "Block/Unblock User" Flag that other users can block and unblock so they stop getting contact emails from (via entityform)
The entityform is set up like (logged in users):
NodeReference: Points to content they are interested in. I use tokens to fill in the authors name, email, etc...
Message: Text message to email field_nodereference:author:mail
So I am trying to create a rule (using the Rules module):
Event: Before saving a entityform submission
Condition:
NOT User has roles: entityform-unchanged:user is administrator (admins can bypass rule)
Entity is of bundle: Parameter: Entity: [entityform-unchanged], Entity type: Entityform Submission, Entity bundle: Contact Article Creator
Entity has field: Parameter: Entity: [entityform-unchanged], Field: field_nodereferencearticle
User is flagged
Parameter: Flag: Block/Unblock User, user: [entityform-unchanged:user], User on whose behalf to check: [entityform-unchanged:field_nodereferencearticle:author
Actions:
Page Redirect to site:url
Show Message: Warning: Was unable to send messsage. The Recipient has blocked you from contacting them.
So the basic premise of this is if a user blocks another user, this rule will preprocess all Contact Article Creator eforms and see if the potential recipient has blocked the user. If so, redirect to the front page with a warning stating the user blocked them.
EDIT 1: However, every eform I submit goes through. I can't get the rule to not submit.
EDIT 2: Here is the actual exported rule.
{ "rules_block_user_from_sending_message_if_user_blocked_them" : {
"LABEL" : "Block user from sending message if user blocked them",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"TAGS" : [ "entityform", "flag" ],
"REQUIRES" : [ "rules", "flag", "entityform" ],
"ON" : { "entityform_presave" : [] },
"IF" : [
{ "entity_is_of_bundle" : {
"entity" : [ "entityform-unchanged" ],
"type" : "entityform",
"bundle" : { "value" : {
"contact_seller" : "contact_seller",
"contact_seller_anonymous" : "contact_seller_anonymous"
}
}
}
},
{ "entity_has_field" : { "entity" : [ "entityform-unchanged" ], "field" : "field_listing" } },
{ "flag_flagged_user" : {
"flag" : "block_unblock_user",
"user" : [ "entityform-unchanged:user" ],
"flagging_user" : [ "entityform-unchanged:field-listing:author" ]
}
}
],
"DO" : [
{ "redirect" : { "url" : [ "site:url" ] } },
{ "drupal_message" : { "message" : "Was unable to send message. ", "type" : "warning" } }
]
} }