One of the most powerful contributed modules available in Drupal 7 (and Drupal 6) is Rules (http://drupal.org/project/rules). The following exports are rules I have created to send out email notifications after saving content to everyone who has indicated they want these notifications in a custom field added to the user account. If it works, you'll receive an email very shortly!
Component action rule:
{ "rules_send_email_after_saving_new_content" : {
"LABEL" : "Send email after saving new content",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "rules" ],
"ON" : [ "node_insert" ],
"DO" : [
{ "variable_add" : {
"USING" : { "type" : "list\u003cuser\u003e" },
"PROVIDE" : { "variable_added" : { "all_users" : "All Users" } }
}
},
{ "LOOP" : {
"USING" : { "list" : [ "all-users" ] },
"ITEM" : { "current_user" : "Current user" },
"DO" : [
{ "component_rules_send_email_to_user" : { "user" : [ "current-user" ], "node" : [ "node" ] } }
]
}
}
]
}
}
Reaction rule:
{ "rules_send_email_after_saving_new_content" : {
"LABEL" : "Send email after saving new content",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "rules" ],
"ON" : [ "node_update", "node_insert" ],
"DO" : [
{ "variable_add" : {
"USING" : { "type" : "boolean", "value" : 1 },
"PROVIDE" : { "variable_added" : { "requested_email" : "Requested email indicator" } }
}
},
{ "entity_query" : {
"USING" : {
"type" : "user",
"property" : "field_new_post_notification",
"value" : [ "requested-email" ],
"limit" : "100"
},
"PROVIDE" : { "entity_fetched" : { "users_to_email" : "Users requesting email updates" } }
}
},
{ "LOOP" : {
"USING" : { "list" : [ "users-to-email" ] },
"ITEM" : { "user_to_notify" : "User to notify" },
"DO" : [
{ "component_rules_send_email_to_user" : { "user" : [ "user-to-notify" ], "node" : [ "node" ] } }
]
}
}
]
}
}

2 Comments
Very good
Submitted by Jamie on
This is all well and good Jonathan but I've read three posts on here now and there hasn't been a single mention of ducks and/or duckpoints. Frankly I feel you are letting the side down and need to do something about it :)
Ducking out
Submitted by guybrush on
I think I'll duck out of giving a proper reply to that
Add new comment