0

This question is similar to others posed, but all the answers I can find appear to refer to Drupal 6, with CCK fields.

I am using Drupal 7 with the Rules module enabled.

I have created a custom Content Type and one of the fields is an Entity Reference, which allows a registered user to be selected as the Content Type is added. Essentially an administrator can associate a registered website user with the content item being added.

I need to email the referenced user when another field value within the Content Type is changed. I'm sure this is possible via the Rules module, but I cannot get the mail to send.

It must be a fairly common situation, emailing a referenced user when a field value is updated, but I have looked at the online notes for the Rules module and cannot find an example of this particular use case.

Has anybody managed to achieve the same outcome as I am seeking?

Thank you.

1
  • Found the solution, but cannot post answer until tomorrow due to low rep. I'll post my answer when the time restriction has passed.
    – MCG
    Commented May 26, 2014 at 22:00

2 Answers 2

2

After some trial and error, I found how to reference the field.

Within the Conditions section of the rule, I needed to:

  • Add "entity has field"
  • Enter "node" within the Data Selector box
  • Select the entity reference field within the Value dropdown

I was then able to refer to the field required, with the mail parameter appended, directly from a standard Send Mail action (i.e. [node:MY-REFERENCED-FIELD:mail]).

0

I would do a custom module to add a function to run in the "To" value field of your rule. Try:

<?php

function my_module_user_lookup($nodeid) {
    $node = node_load($nodeid);
    $userid = $node->YOUR_FIELD_NAME_HERE['und'][0]['target_id'];
    $user = user_load($userid);

    return $user->mail; 
}
?>

Then in your rule add this php function (make sure to run it as PHP to your To field. I believe <?php my_module_user_lookup($node->id); ?> should do it. From there you just need to add the logic for sending when the node is updated, but that is all apart of rules.

1
  • Thank you for the suggestion. I found a solution and have posted that, but I'm sure this would achieve the same outcome. Thanks
    – MCG
    Commented May 27, 2014 at 7:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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