Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / hook / mail.twig
1 /**
2  * Implements hook_mail().
3  */
4 function {{ machine_name }}_mail($key, &$message, $params) {
5   $account = $params['account'];
6   $context = $params['context'];
7   $variables = [
8     '%site_name' => \Drupal::config('system.site')->get('name'),
9     '%username' => $account->getDisplayName(),
10   ];
11   if ($context['hook'] == 'taxonomy') {
12     $entity = $params['entity'];
13     $vocabulary = Vocabulary::load($entity->id());
14     $variables += [
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(),
21     ];
22   }
23
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'];
28     $variables += [
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,
35     ];
36   }
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);
41 }