From 59cdf07c7e4589480b7eb228d40db71916e449a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 28 Jan 2022 16:23:41 +0100 Subject: [PATCH] add form in notification thread inside entities show --- .../NotificationTwigExtensionRuntime.php | 30 +++++++++++++++++-- ...extension_list_notifications_for.html.twig | 6 ++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Notification/Templating/NotificationTwigExtensionRuntime.php b/src/Bundle/ChillMainBundle/Notification/Templating/NotificationTwigExtensionRuntime.php index d5ec75699..1e52e128e 100644 --- a/src/Bundle/ChillMainBundle/Notification/Templating/NotificationTwigExtensionRuntime.php +++ b/src/Bundle/ChillMainBundle/Notification/Templating/NotificationTwigExtensionRuntime.php @@ -11,17 +11,27 @@ declare(strict_types=1); namespace Chill\MainBundle\Notification\Templating; +use Chill\MainBundle\Entity\NotificationComment; +use Chill\MainBundle\Form\NotificationCommentType; use Chill\MainBundle\Notification\NotificationPresence; +use Symfony\Component\Form\FormFactoryInterface; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Twig\Environment; use Twig\Extension\RuntimeExtensionInterface; class NotificationTwigExtensionRuntime implements RuntimeExtensionInterface { + private FormFactoryInterface $formFactory; + private NotificationPresence $notificationPresence; - public function __construct(NotificationPresence $notificationPresence) + private UrlGeneratorInterface $urlGenerator; + + public function __construct(FormFactoryInterface $formFactory, NotificationPresence $notificationPresence, UrlGeneratorInterface $urlGenerator) { + $this->formFactory = $formFactory; $this->notificationPresence = $notificationPresence; + $this->urlGenerator = $urlGenerator; } public function counterNotificationFor(Environment $environment, string $relatedEntityClass, int $relatedEntityId, array $options = []): string @@ -47,8 +57,24 @@ class NotificationTwigExtensionRuntime implements RuntimeExtensionInterface return ''; } + $appendCommentForms = []; + + foreach ($notifications as $notification) { + $appendComment = new NotificationComment(); + $appendCommentForms[$notification->getId()] = $this->formFactory->create( + NotificationCommentType::class, + $appendComment, + [ + 'action' => $this->urlGenerator->generate( + 'chill_main_notification_show', + ['id' => $notification->getId()] + ), + ] + )->createView(); + } + return $environment->render('@ChillMain/Notification/extension_list_notifications_for.html.twig', [ - 'notifications' => $notifications, + 'notifications' => $notifications, 'appendCommentForms' => $appendCommentForms, ]); } } diff --git a/src/Bundle/ChillMainBundle/Resources/views/Notification/extension_list_notifications_for.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Notification/extension_list_notifications_for.html.twig index de25fb236..15462d516 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Notification/extension_list_notifications_for.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Notification/extension_list_notifications_for.html.twig @@ -5,8 +5,10 @@ {% include 'ChillMainBundle:Notification:_list_item.html.twig' with { 'full_content': true, 'fold_item': true, - 'action_button': true, - 'with_folded_comments': false + 'action_button': false, + 'with_folded_comments': true, + 'appendCommentForm': appendCommentForms[notification.id], + 'editedCommentForm': null, } %}{# #} {% endfor %}