1010
1111use Ibexa \Contracts \Core \Repository \Values \Notification \Notification ;
1212use Ibexa \Core \Notification \Renderer \NotificationRenderer ;
13+ use Ibexa \Core \Notification \Renderer \TypedNotificationRendererInterface ;
14+ use JMS \TranslationBundle \Annotation \Desc ;
15+ use Symfony \Component \HttpFoundation \RequestStack ;
1316use Symfony \Component \Routing \Generator \UrlGeneratorInterface ;
17+ use Symfony \Contracts \Translation \TranslatorInterface ;
1418use Twig \Environment ;
1519
16- final class SystemNotificationRenderer implements NotificationRenderer
20+ final class SystemNotificationRenderer implements NotificationRenderer, TypedNotificationRendererInterface
1721{
1822 private const KEY_ICON = 'icon ' ;
1923 private const KEY_ROUTE_NAME = 'route_name ' ;
@@ -25,14 +29,31 @@ final class SystemNotificationRenderer implements NotificationRenderer
2529
2630 private UrlGeneratorInterface $ urlGenerator ;
2731
28- public function __construct (Environment $ twig , UrlGeneratorInterface $ urlGenerator )
29- {
32+ private RequestStack $ requestStack ;
33+
34+ private TranslatorInterface $ translator ;
35+
36+ public function __construct (
37+ Environment $ twig ,
38+ UrlGeneratorInterface $ urlGenerator ,
39+ RequestStack $ requestStack ,
40+ TranslatorInterface $ translator
41+ ) {
3042 $ this ->twig = $ twig ;
3143 $ this ->urlGenerator = $ urlGenerator ;
44+ $ this ->requestStack = $ requestStack ;
45+ $ this ->translator = $ translator ;
3246 }
3347
3448 public function render (Notification $ notification ): string
3549 {
50+ $ baseTemplate = '@ibexadesign/account/notifications/list_item.html.twig ' ;
51+
52+ $ currentRequest = $ this ->requestStack ->getCurrentRequest ();
53+ if ($ currentRequest !== null && $ currentRequest ->attributes ->getBoolean ('render_all ' )) {
54+ $ baseTemplate = '@ibexadesign/account/notifications/list_item_all.html.twig ' ;
55+ }
56+
3657 return $ this ->twig ->render (
3758 '@ibexadesign/notification/system_notification.html.twig ' ,
3859 [
@@ -41,6 +62,7 @@ public function render(Notification $notification): string
4162 'content ' => $ notification ->data [self ::KEY_CONTENT ] ?? null ,
4263 'subject ' => $ notification ->data [self ::KEY_SUBJECT ] ?? null ,
4364 'created_at ' => $ notification ->created ,
65+ 'base_template ' => $ baseTemplate ,
4466 ]
4567 );
4668 }
@@ -56,4 +78,14 @@ public function generateUrl(Notification $notification): ?string
5678 $ notification ->data [self ::KEY_ROUTE_PARAMS ] ?? []
5779 );
5880 }
81+
82+ public function getTypeLabel (): string
83+ {
84+ return $ this ->translator ->trans (
85+ /** @Desc("System notification") */
86+ 'notifications.notification.system.label ' ,
87+ [],
88+ 'ibexa_notifications '
89+ );
90+ }
5991}
0 commit comments