From 3c3576c2970787290855eabff5517b6388b6e590 Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov <38059171+askvortsov1@users.noreply.github.com> Date: Mon, 28 Sep 2020 00:04:28 -0400 Subject: [PATCH] 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 --- .../core/src/Notification/MailableInterface.php | 6 +++++- .../core/src/Notification/NotificationMailer.php | 14 +++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/framework/core/src/Notification/MailableInterface.php b/framework/core/src/Notification/MailableInterface.php index cfe7ab042..14360d757 100644 --- a/framework/core/src/Notification/MailableInterface.php +++ b/framework/core/src/Notification/MailableInterface.php @@ -9,6 +9,8 @@ namespace Flarum\Notification; +use Symfony\Component\Translation\TranslatorInterface; + interface MailableInterface { /** @@ -23,5 +25,7 @@ interface MailableInterface * * @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); } diff --git a/framework/core/src/Notification/NotificationMailer.php b/framework/core/src/Notification/NotificationMailer.php index c298a8c78..20464b712 100644 --- a/framework/core/src/Notification/NotificationMailer.php +++ b/framework/core/src/Notification/NotificationMailer.php @@ -12,6 +12,7 @@ namespace Flarum\Notification; use Flarum\User\User; use Illuminate\Contracts\Mail\Mailer; use Illuminate\Mail\Message; +use Symfony\Component\Translation\TranslatorInterface; class NotificationMailer { @@ -21,11 +22,18 @@ class NotificationMailer 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->translator = $translator; } /** @@ -39,7 +47,7 @@ class NotificationMailer compact('blueprint', 'user'), function (Message $message) use ($blueprint, $user) { $message->to($user->email, $user->username) - ->subject($blueprint->getEmailSubject()); + ->subject($blueprint->getEmailSubject($this->translator)); } ); }