1616use Ibexa \Contracts \Notifications \Value \Recipent \UserRecipient ;
1717use Ibexa \Contracts \User \Notification \UserPasswordReset ;
1818use Ibexa \Contracts \User \PasswordReset \NotifierInterface ;
19+ use InvalidArgumentException ;
20+ use Psr \Log \LoggerAwareInterface ;
21+ use Psr \Log \LoggerAwareTrait ;
1922use Swift_Image ;
2023use Swift_Mailer ;
2124use Swift_Message ;
25+ use Symfony \Component \HttpKernel \KernelInterface ;
2226use Twig \Environment ;
2327
24- class PasswordReset implements NotifierInterface
28+ class PasswordReset implements NotifierInterface, LoggerAwareInterface
2529{
30+ use LoggerAwareTrait;
31+
2632 private ConfigResolverInterface $ configResolver ;
2733
2834 private Swift_Mailer $ mailer ;
@@ -31,20 +37,33 @@ class PasswordReset implements NotifierInterface
3137
3238 private NotificationServiceInterface $ notificationService ;
3339
34- private string $ projectDir ;
40+ private KernelInterface $ kernel ;
3541
3642 public function __construct (
3743 ConfigResolverInterface $ configResolver ,
3844 Swift_Mailer $ mailer ,
3945 Environment $ twig ,
4046 NotificationServiceInterface $ notificationService ,
41- string $ projectDir
47+ KernelInterface $ kernel
4248 ) {
4349 $ this ->configResolver = $ configResolver ;
4450 $ this ->mailer = $ mailer ;
4551 $ this ->twig = $ twig ;
4652 $ this ->notificationService = $ notificationService ;
47- $ this ->projectDir = $ projectDir ;
53+ $ this ->kernel = $ kernel ;
54+ }
55+
56+ private function locateMailImage (string $ imageName ): string
57+ {
58+ try {
59+ return $ this ->kernel ->locateResource ('@IbexaAdminUiBundle/Resources/public/img/mail/ ' . $ imageName );
60+ } catch (InvalidArgumentException $ e ) {
61+ if ($ this ->logger ) {
62+ $ this ->logger ->error ('Failed to locate mail image: ' . $ imageName , ['exception ' => $ e ]);
63+ }
64+
65+ return '# ' ;
66+ }
4867 }
4968
5069 public function sendMessage (User $ user , string $ hashKey ): void
@@ -55,7 +74,6 @@ public function sendMessage(User $user, string $hashKey): void
5574 return ;
5675 }
5776
58- // Swiftmailer delivery has to be kept to maintain backwards compatibility
5977 $ template = $ this ->twig ->load ($ this ->configResolver ->getParameter ('user_forgot_password.templates.mail ' ));
6078
6179 $ senderAddress = $ this ->configResolver ->hasParameter ('sender_address ' , 'swiftmailer.mailer ' )
@@ -69,9 +87,7 @@ public function sendMessage(User $user, string $hashKey): void
6987 ->setSubject ($ subject )
7088 ->setTo ($ user ->email );
7189
72- $ embeddedHeader = $ message ->embed (Swift_Image::fromPath (
73- $ this ->projectDir . '/public/bundles/ibexaadminui/img/mail/header.png '
74- ));
90+ $ embeddedHeader = $ message ->embed (Swift_Image::fromPath ($ this ->locateMailImage ('header.png ' )));
7591
7692 $ body = $ template ->renderBlock ('body ' , [
7793 'hash_key ' => $ hashKey ,
0 commit comments