From f43d79c94080e7b3db74be59eb6cd0398c45b269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 10 Jun 2024 15:23:54 +0200 Subject: [PATCH] Add notification date to entity render strings The notification date has been added to the render strings of entities involved in the notifications, specifically for the sender, addressees, and normalizer. This is done by passing it as a parameter to the 'chill_entity_render_string' function and the 'normalize' function in NotificationNormalizer. This will help provide more context regarding the time of the events in the notification. --- .../Resources/views/Notification/_list_item.html.twig | 4 ++-- .../Resources/views/Notification/show.html.twig | 2 +- .../Serializer/Normalizer/NotificationNormalizer.php | 2 +- src/Bundle/ChillMainBundle/Templating/Entity/UserRender.php | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Resources/views/Notification/_list_item.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Notification/_list_item.html.twig index 9bec09e4c..377c693ff 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Notification/_list_item.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Notification/_list_item.html.twig @@ -21,7 +21,7 @@ {% if not c.notification.isSystem %} - {{ c.notification.sender|chill_entity_render_string }} + {{ c.notification.sender|chill_entity_render_string({'at_date': c.notification.date}) }} {% else %} {{ 'notification.is_system'|trans }} @@ -53,7 +53,7 @@ {% endif %} {% for a in c.notification.addressees %} - {{ a|chill_entity_render_string }} + {{ a|chill_entity_render_string({'at_date': c.notification.date}) }} {% endfor %} {% for a in c.notification.addressesEmails %} diff --git a/src/Bundle/ChillMainBundle/Resources/views/Notification/show.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Notification/show.html.twig index 53e296d8d..e3aa98329 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Notification/show.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Notification/show.html.twig @@ -1,7 +1,7 @@ {% extends "@ChillMain/layout.html.twig" %} {% block title 'notification.show notification from %sender%'|trans( - { '%sender%': notification.sender|chill_entity_render_string } + { '%sender%': notification.sender|chill_entity_render_string({'at_date': notification.date}) } ) ~ ' ' ~ notification.title %} {% block js %} diff --git a/src/Bundle/ChillMainBundle/Serializer/Normalizer/NotificationNormalizer.php b/src/Bundle/ChillMainBundle/Serializer/Normalizer/NotificationNormalizer.php index 70cd9a838..a19cd6778 100644 --- a/src/Bundle/ChillMainBundle/Serializer/Normalizer/NotificationNormalizer.php +++ b/src/Bundle/ChillMainBundle/Serializer/Normalizer/NotificationNormalizer.php @@ -47,7 +47,7 @@ class NotificationNormalizer implements NormalizerAwareInterface, NormalizerInte 'message' => $object->getMessage(), 'relatedEntityClass' => $object->getRelatedEntityClass(), 'relatedEntityId' => $object->getRelatedEntityId(), - 'sender' => $this->normalizer->normalize($object->getSender(), $format, $context), + 'sender' => $this->normalizer->normalize($object->getSender(), $format, [...$context, UserNormalizer::AT_DATE => $object->getDate()]), 'title' => $object->getTitle(), 'entity' => null !== $entity ? $this->normalizer->normalize($entity, $format, $context) : null, ]; diff --git a/src/Bundle/ChillMainBundle/Templating/Entity/UserRender.php b/src/Bundle/ChillMainBundle/Templating/Entity/UserRender.php index 3edd56512..949d0c052 100644 --- a/src/Bundle/ChillMainBundle/Templating/Entity/UserRender.php +++ b/src/Bundle/ChillMainBundle/Templating/Entity/UserRender.php @@ -14,7 +14,7 @@ namespace Chill\MainBundle\Templating\Entity; use Chill\MainBundle\Entity\User; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use DateTime; -use Monolog\DateTimeImmutable; +use DateTimeImmutable; use Symfony\Component\Clock\ClockInterface; use Symfony\Contracts\Translation\TranslatorInterface; use Twig\Error\LoaderError;