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.

  • Going to post this here, answering my own question. Not sure if this is hacky or not but I worked around my inability to access the node fields by having the comment update the node changed to the current time. Then created a new rule to fire an email off to the entity reference user on that update. ¯_(ツ)_/¯
    – rd89
    May 12 at 17:34
  • That is definitely hacky :).
    – anoopjohn
    May 12 at 21:20
  • @anoopjohn want to send a little guidance? I will send a cup of coffee for your effort :)
    – rd89
    May 13 at 6:18

1 Answer 1


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.