Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d7 / 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 = array(
8     '%site_name' => variable_get('site_name', 'Drupal'),
9     '%username' => format_username($account),
10   );
11   if ($context['hook'] == 'taxonomy') {
12     $entity = $params['entity'];
13     $vocabulary = taxonomy_vocabulary_load($entity->vid);
14     $variables += array(
15       '%term_name' => $entity->name,
16       '%term_description' => $entity->description,
17       '%term_id' => $entity->tid,
18       '%vocabulary_name' => $vocabulary->name,
19       '%vocabulary_description' => $vocabulary->description,
20       '%vocabulary_id' => $vocabulary->vid,
21     );
22   }
23
24   // Node-based variable translation is only available if we have a node.
25   if (isset($params['node'])) {
26     $node = $params['node'];
27     $variables += array(
28       '%uid' => $node->uid,
29       '%node_url' => url('node/' . $node->nid, array('absolute' => TRUE)),
30       '%node_type' => node_type_get_name($node),
31       '%title' => $node->title,
32       '%teaser' => $node->teaser,
33       '%body' => $node->body,
34     );
35   }
36   $subject = strtr($context['subject'], $variables);
37   $body = strtr($context['message'], $variables);
38   $message['subject'] .= str_replace(array("\r", "\n"), '', $subject);
39   $message['body'][] = drupal_html_to_text($body);
40 }