On a Drupal 8 site, I have a content type called TeamMember which has an email field. From the view where I show all the TeamMembers, I'd like to link to a form where the user can email that person directly. Is there a way to customize the recipient of the email from a contact form?
What we do in a few places is to have a hidden reference field to the team node in your contact message entity.
Then you pre-fill that when displaying the contact form and later on in hook_mail_alter(), use that information to change the recipient.
Requires a bit of custom code but then you don't have to create a lot of contact forms.
Contact forms in D8 don't have customizable recipients out of the box so you're going to need some sort of workaround.
A couple of paths that you could take:
- Treat your TeamMember not as Node entities, but as User entities. Use their profile page (/user/X) as the content page and use the personal contact form (/user/X/contact) as the per-TeamMember contact form.
- Keep the TeamMember, but create a unique contact form for each TeamMember. On the TeamMember node type, create a Link field that links to each unique contact form you've built.