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 f1360a1394
commit efd68df13a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 4 deletions

View File

@ -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);
}

View File

@ -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));
}
);
}