Skip to content

Commit

Permalink
[Mailer] default translations tokent for call to action template
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoiriert committed Dec 7, 2023
1 parent d92919a commit 079d312
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 11 deletions.
19 changes: 19 additions & 0 deletions app/src/Mailer/UserNameFromEmailEmailWriter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Mailer;

use Draw\Component\Mailer\Email\CallToActionEmail;
use Draw\Component\Mailer\EmailWriter\EmailWriterInterface;

class UserNameFromEmailEmailWriter implements EmailWriterInterface
{
public static function getForEmails(): array
{
return ['compose' => -255];
}

public function compose(CallToActionEmail $email): void
{
$email->translationTokens['%user_name%'] = 'John Doe';
}
}
4 changes: 4 additions & 0 deletions packages/mailer/Email/CallToActionEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ class CallToActionEmail extends TemplatedEmail
{
private ?string $callToActionLink = null;

public array $translationTokens = [];

public function getContext(): array
{
$context = parent::getContext();

$context['call_to_action_link'] = $this->callToActionLink;

$context['translation_tokens'] = $this->translationTokens;

return $context;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/mailer/Resources/translations/DrawEmail.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ email:
bottom_section: ''
signature: '<p>Thanks!</p>'
company_address: 'Company Inc, 3 Abbey Road, San Francisco CA 94102'
unsubscribe: '<br />Don''t like these emails? <a href="%link%">Unsubscribe</a>.'
unsubscribe: '<br />Don''t like these emails? <a href="%unsubscribe_link%">Unsubscribe</a>.'
2 changes: 1 addition & 1 deletion packages/mailer/Resources/translations/DrawEmail.fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ email:
bottom_section: ''
signature: '<p>Merci !</p>'
company_address: 'Company Inc, 3 Abbey Road, San Francisco CA 94102'
unsubscribe: '<br />Vous ne voulez pas recevoir ces courriels ? <a href="%link%">Se désabonner</a>.'
unsubscribe: '<br />Vous ne voulez pas recevoir ces courriels ? <a href="%unsubscribe_link%">Se désabonner</a>.'
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% trans_default_domain 'DrawEmail' %}
{% set draw_email_name = draw_email_name|default('default') %}
{% set translation_tokens = translation_tokens|default({}) %}
{% set _tokens = {
'subject': ['email.' ~ draw_email_name ~ '.subject', 'email.default.subject'],
'preview': ['email.' ~ draw_email_name ~ '.preview', 'email.default.preview'],
Expand All @@ -16,7 +17,7 @@
<head>
<meta name="viewport" content="width=device-width" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>{% block subject %}{{ _tokens.subject|trans|raw }}{% endblock subject %}</title>
<title>{% block subject %}{{ _tokens.subject|trans(translation_tokens)|raw }}{% endblock subject %}</title>
{% block style %}
<style>
/* -------------------------------------
Expand Down Expand Up @@ -348,7 +349,7 @@
{% endblock style %}
</head>
<body class="">
<span class="preheader">{% block preview %}{{ _tokens.preview|trans|raw }}{% endblock preview %}</span>
<span class="preheader">{% block preview %}{{ _tokens.preview|trans(translation_tokens)|raw }}{% endblock preview %}</span>
<table role="presentation" border="0" cellpadding="0" cellspacing="0" class="body">
<tr>
<td>&nbsp;</td>
Expand All @@ -364,8 +365,8 @@
<table role="presentation" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
{% block salutation %}{{ _tokens.salutation|trans|raw }}{% endblock salutation %}
{% block top_section %}{{ _tokens.top_section|trans|raw }}{% endblock top_section %}
{% block salutation %}{{ _tokens.salutation|trans(translation_tokens)|raw }}{% endblock salutation %}
{% block top_section %}{{ _tokens.top_section|trans(translation_tokens)|raw }}{% endblock top_section %}
{% block call_to_action %}
<table role="presentation" border="0" cellpadding="0" cellspacing="0" class="btn btn-primary">
<tbody>
Expand All @@ -374,7 +375,7 @@
<table role="presentation" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td> <a href="{{ call_to_action_link }}" target="_blank">{% block call_to_action_text %}{{ _tokens.call_to_action_text|trans|raw }}{% endblock call_to_action_text %}</a></td>
<td> <a href="{{ call_to_action_link }}" target="_blank">{% block call_to_action_text %}{{ _tokens.call_to_action_text|trans(translation_tokens)|raw }}{% endblock call_to_action_text %}</a></td>
</tr>
</tbody>
</table>
Expand All @@ -383,8 +384,8 @@
</tbody>
</table>
{% endblock call_to_action %}
{% block bottom_section %}{{ _tokens.bottom_section|trans|raw }}{% endblock bottom_section %}
{% block signature %}{{ _tokens.signature|trans|raw }}{% endblock signature %}
{% block bottom_section %}{{ _tokens.bottom_section|trans(translation_tokens)|raw }}{% endblock bottom_section %}
{% block signature %}{{ _tokens.signature|trans(translation_tokens)|raw }}{% endblock signature %}
</td>
</tr>
</table>
Expand All @@ -400,10 +401,10 @@
<table role="presentation" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="content-block">
<span class="apple-link">{% block company_address %}{{ _tokens.company_address|trans|raw }}{% endblock company_address %}</span>
<span class="apple-link">{% block company_address %}{{ _tokens.company_address|trans(translation_tokens)|raw }}{% endblock company_address %}</span>
{% block unsubscribe %}
{% if unsubscribe_link is defined %}
{{ _tokens.unsubscribe|trans({'%link%': unsubscribe_link})|raw }}
{{ _tokens.unsubscribe|trans(translation_tokens|merge({'%unsubscribe_link%': unsubscribe_link}))|raw }}
{% endif %}
{% endblock unsubscribe %}
</td>
Expand Down
1 change: 1 addition & 0 deletions translations/DrawEmail.en.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
email:
default:
salutation: '<p>Bonjour %user_name%,</p>'
company_address: 'Santa Claus, North Pole H0H 0H0, Canada'

0 comments on commit 079d312

Please sign in to comment.