0

I'am looking for a way to insert a node title to mail message sent by contact form in Drupal 8.

A contact form is inserted into my node as a field. It is used on each node to receive mail from users. But I need to specify what node the email was sent with.

I use MYMODULE_mail_alter to format mail message. How can i insert node title to mail subject and body?

Or is it possible to get node title in MYTHEME_form_alter ?

1 Answer 1

1

The current node is available from the route match, \Drupal::routeMatch()->getParameter('node'). Make sure it really is an instance of NodeInterface before you continue or check the route name.

Then it's easy to use $node->getTitle() as the default value for the subject of the contact form. Depending on what you want to do, you can then also hide the subject field.

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.