annotate vendor/chi-teck/drupal-code-generator/templates/d8/hook/mail.twig @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents c75dbcec494b
children
rev   line source
Chris@0 1 /**
Chris@0 2 * Implements hook_mail().
Chris@0 3 */
Chris@0 4 function {{ machine_name }}_mail($key, &$message, $params) {
Chris@0 5 $account = $params['account'];
Chris@0 6 $context = $params['context'];
Chris@0 7 $variables = [
Chris@0 8 '%site_name' => \Drupal::config('system.site')->get('name'),
Chris@0 9 '%username' => $account->getDisplayName(),
Chris@0 10 ];
Chris@0 11 if ($context['hook'] == 'taxonomy') {
Chris@0 12 $entity = $params['entity'];
Chris@0 13 $vocabulary = Vocabulary::load($entity->id());
Chris@0 14 $variables += [
Chris@0 15 '%term_name' => $entity->name,
Chris@0 16 '%term_description' => $entity->description,
Chris@0 17 '%term_id' => $entity->id(),
Chris@0 18 '%vocabulary_name' => $vocabulary->label(),
Chris@0 19 '%vocabulary_description' => $vocabulary->getDescription(),
Chris@0 20 '%vocabulary_id' => $vocabulary->id(),
Chris@0 21 ];
Chris@0 22 }
Chris@0 23
Chris@0 24 // Node-based variable translation is only available if we have a node.
Chris@0 25 if (isset($params['node'])) {
Chris@0 26 /** @var \Drupal\node\NodeInterface $node */
Chris@0 27 $node = $params['node'];
Chris@0 28 $variables += [
Chris@0 29 '%uid' => $node->getOwnerId(),
Chris@0 30 '%url' => $node->url('canonical', ['absolute' => TRUE]),
Chris@0 31 '%node_type' => node_get_type_label($node),
Chris@0 32 '%title' => $node->getTitle(),
Chris@0 33 '%teaser' => $node->teaser,
Chris@0 34 '%body' => $node->body,
Chris@0 35 ];
Chris@0 36 }
Chris@0 37 $subject = strtr($context['subject'], $variables);
Chris@0 38 $body = strtr($context['message'], $variables);
Chris@0 39 $message['subject'] .= str_replace(["\r", "\n"], '', $subject);
Chris@0 40 $message['body'][] = MailFormatHelper::htmlToText($body);
Chris@0 41 }