add form in notification thread inside entities show

This commit is contained in:
Julien Fastré 2022-01-28 16:23:41 +01:00
parent 7f41f14959
commit 59cdf07c7e
2 changed files with 32 additions and 4 deletions

View File

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

View File

@ -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 %}