2 * Implements hook_mail().
4 function {{ machine_name }}_mail($key, &$message, $params) {
5 $account = $params['account'];
6 $context = $params['context'];
8 '%site_name' => \Drupal::config('system.site')->get('name'),
9 '%username' => $account->getDisplayName(),
11 if ($context['hook'] == 'taxonomy') {
12 $entity = $params['entity'];
13 $vocabulary = Vocabulary::load($entity->id());
15 '%term_name' => $entity->name,
16 '%term_description' => $entity->description,
17 '%term_id' => $entity->id(),
18 '%vocabulary_name' => $vocabulary->label(),
19 '%vocabulary_description' => $vocabulary->getDescription(),
20 '%vocabulary_id' => $vocabulary->id(),
24 // Node-based variable translation is only available if we have a node.
25 if (isset($params['node'])) {
26 /** @var \Drupal\node\NodeInterface $node */
27 $node = $params['node'];
29 '%uid' => $node->getOwnerId(),
30 '%url' => $node->url('canonical', ['absolute' => TRUE]),
31 '%node_type' => node_get_type_label($node),
32 '%title' => $node->getTitle(),
33 '%teaser' => $node->teaser,
34 '%body' => $node->body,
37 $subject = strtr($context['subject'], $variables);
38 $body = strtr($context['message'], $variables);
39 $message['subject'] .= str_replace(["\r", "\n"], '', $subject);
40 $message['body'][] = MailFormatHelper::htmlToText($body);