The "entity_has_field
" is indeed the "clue" to answer your question.
Here is a sample of such rule (in Rules export format), which will send an eMail to the userid selected via the field field_blog_reviewer
(= a field I added to my "Blog" content type that is defined as an entity reference to a 'user'), and this whenever a new node of content type "Blog" is saved:
{ "rules_notify_reviewer_about_outstanding_approval" : {
"LABEL" : "Notify reviewer about outstanding approval",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules" ],
"ON" : { "node_insert--blog" : { "bundle" : "blog" } },
"IF" : [
{ "entity_has_field" : { "entity" : [ "node" ], "field" : "field_blog_reviewer" } }
],
"DO" : [
{ "mail" : {
"to" : "[node:field-blog-reviewer]",
"subject" : "Blog Post waiting your approval",
"message" : "[node:author] has submitted a new Blog post waiting your approval.\r\n\r\nYou can review it at: [node:edit-url].",
"language" : [ "" ]
}
}
]
}
}
Should you be interested in using the above rule, just use the Rules UI to "import" it. However, before doing so, make sure to first add a field with machine name field_blog_reviewer
to content type named blog
(this content type gets added automatically if you enable the "Blog" module).
If you try to import it without doing this, the rules "import" will fail with some type of integrity check error (in plain English: the import is rejected if the entity doesn't exist, and/or it doesn't have a field with the exact machine name). As a workaround you may also edit the exported rule above before starting the import, to make it fit the machine names of the field and the content type you want to use it for.