I have a content type with a user reference field on it, the users are populated here by a view.
When a user saves a comment, I want to access that field and send an email to user in the entity reference field.
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityI have a content type with a user reference field on it, the users are populated here by a view.
When a user saves a comment, I want to access that field and send an email to user in the entity reference field.
Although the question is about doing this with rules, here is how you can do this with some custom code. There could be a rules based approach towards doing the same thing.
You can implement a hook_ENTITY_TYPE_insert hook in your module which will get called when a comment is inserted and then from that comment, get the node and from there you can do whatever you want to do with the node.
function custom_module_comment_insert(\Drupal\Core\Entity\EntityInterface $entity) {
// $entity will be a comment entity.
$node = $entity->getCommentedEntity();
if ($commented_entity && $commented_entity instanceof \Drupal\node\NodeInterface) {
// Do what you want to do with the node
}
}
Hope this helps somebody running into this post.