Skip to content

Commit

Permalink
Pass a translator instance to getEmailSubject on MailableInterface (#…
Browse files Browse the repository at this point in the history
…2244)

* Pass a translator instance to getMailSubject (breaking change)

* Temporarily comment out getEmailSubject to avoid BC breaks
  • Loading branch information
askvortsov1 authored Sep 28, 2020
1 parent e39e39c commit 7b43c60
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/Notification/MailableInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace Flarum\Notification;

use Symfony\Component\Translation\TranslatorInterface;

interface MailableInterface
{
/**
Expand All @@ -23,5 +25,7 @@ public function getEmailView();
*
* @return string
*/
public function getEmailSubject();
// TODO: This is temporarily commented out to avoid BC breaks between beta 13 and beta 14.
// It should be uncommented before beta 15.
// public function getEmailSubject(TranslatorInterface $translator);
}
12 changes: 10 additions & 2 deletions src/Notification/NotificationMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Flarum\User\User;
use Illuminate\Contracts\Mail\Mailer;
use Illuminate\Mail\Message;
use Symfony\Component\Translation\TranslatorInterface;

class NotificationMailer
{
Expand All @@ -20,12 +21,19 @@ class NotificationMailer
*/
protected $mailer;

/**
* @var TranslatorInterface
*/
protected $translator;

/**
* @param Mailer $mailer
* @param TranslatorInterface $translator
*/
public function __construct(Mailer $mailer)
public function __construct(Mailer $mailer, TranslatorInterface $translator)
{
$this->mailer = $mailer;
$this->translator = $translator;
}

/**
Expand All @@ -39,7 +47,7 @@ public function send(MailableInterface $blueprint, User $user)
compact('blueprint', 'user'),
function (Message $message) use ($blueprint, $user) {
$message->to($user->email, $user->username)
->subject($blueprint->getEmailSubject());
->subject($blueprint->getEmailSubject($this->translator));
}
);
}
Expand Down

0 comments on commit 7b43c60

Please sign in to comment.