How do I code a function for sending mail containing a rendered entity that is referenced from a field?
I have content type A that contains static information, and content type B that users create and reference to the corresponding content type A node instead of writing everything manually. In a custom module I have some code for sending mail notifications containing info in a content type B node, but now the client wants some info from the referenced content type A node.
The line of code that I have a problem is this:
$avtal_id = $node->field_avtalsnummer['und']['value'];
field_avtalsnummer is the reference field in content type B that points to a node of type A and
$avtal_id is used in the mail (plain-text). All other fields in the custom module works fine, but for some reason that I don't fully understand I can't get this to work. If I change
target_id i get the node ID but I can't get the value. Title does not work either. Do I need some code to load the entity first? The optimal solution for me would be to get the info from the referenced field and to display a custom view mode so that I can customise the mail notification accordingly to my clients demands, but I can't even get the value of of the referenced field to work so I'm running out of ideas. Help is very appreciated!