Pass a translator instance to getEmailSubject on MailableInterface (#2244)

* Pass a translator instance to getMailSubject (breaking change)

* Temporarily comment out getEmailSubject to avoid BC breaks
This commit is contained in:
Alexander Skvortsov 2020-09-28 00:04:28 -04:00 committed by GitHub
parent 1dfb01d067
commit 3c3576c297
2 changed files with 16 additions and 4 deletions

View File

@ -9,6 +9,8 @@
namespace Flarum\Notification; namespace Flarum\Notification;
use Symfony\Component\Translation\TranslatorInterface;
interface MailableInterface interface MailableInterface
{ {
/** /**
@ -23,5 +25,7 @@ interface MailableInterface
* *
* @return string * @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);
} }

View File

@ -12,6 +12,7 @@ namespace Flarum\Notification;
use Flarum\User\User; use Flarum\User\User;
use Illuminate\Contracts\Mail\Mailer; use Illuminate\Contracts\Mail\Mailer;
use Illuminate\Mail\Message; use Illuminate\Mail\Message;
use Symfony\Component\Translation\TranslatorInterface;
class NotificationMailer class NotificationMailer
{ {
@ -21,11 +22,18 @@ class NotificationMailer
protected $mailer; protected $mailer;
/** /**
* @param Mailer $mailer * @var TranslatorInterface
*/ */
public function __construct(Mailer $mailer) protected $translator;
/**
* @param Mailer $mailer
* @param TranslatorInterface $translator
*/
public function __construct(Mailer $mailer, TranslatorInterface $translator)
{ {
$this->mailer = $mailer; $this->mailer = $mailer;
$this->translator = $translator;
} }
/** /**
@ -39,7 +47,7 @@ class NotificationMailer
compact('blueprint', 'user'), compact('blueprint', 'user'),
function (Message $message) use ($blueprint, $user) { function (Message $message) use ($blueprint, $user) {
$message->to($user->email, $user->username) $message->to($user->email, $user->username)
->subject($blueprint->getEmailSubject()); ->subject($blueprint->getEmailSubject($this->translator));
} }
); );
} }