diff --git a/src/Bundle/ChillMainBundle/Controller/NotificationController.php b/src/Bundle/ChillMainBundle/Controller/NotificationController.php index 52f58ed68..793810463 100644 --- a/src/Bundle/ChillMainBundle/Controller/NotificationController.php +++ b/src/Bundle/ChillMainBundle/Controller/NotificationController.php @@ -235,6 +235,8 @@ class NotificationController extends AbstractController 'id' => $notification->getId(), '_fragment' => 'comment-' . $commentId, ]); + } elseif ($editedCommentForm->isSubmitted() && !$editedCommentForm->isValid()) { + $this->addFlash('error', $this->translator->trans('This form contains errors')); } } } @@ -256,6 +258,8 @@ class NotificationController extends AbstractController return $this->redirectToRoute('chill_main_notification_show', [ 'id' => $notification->getId(), ]); + } elseif ($appendCommentForm->isSubmitted() && !$appendCommentForm->isValid()) { + $this->addFlash('error', $this->translator->trans('This form contains errors')); } } } diff --git a/src/Bundle/ChillMainBundle/Entity/NotificationComment.php b/src/Bundle/ChillMainBundle/Entity/NotificationComment.php index 01911c729..5275010e6 100644 --- a/src/Bundle/ChillMainBundle/Entity/NotificationComment.php +++ b/src/Bundle/ChillMainBundle/Entity/NotificationComment.php @@ -18,6 +18,7 @@ use DateTimeInterface; use Doctrine\ORM\Event\LifecycleEventArgs; use Doctrine\ORM\Event\PreFlushEventArgs; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Validator\Constraints as Assert; /** * @ORM\Entity @@ -28,6 +29,7 @@ class NotificationComment implements TrackCreationInterface, TrackUpdateInterfac { /** * @ORM\Column(type="text") + * @Assert\NotBlank(message="notification.Comment content might not be blank") */ private string $content = ''; @@ -136,9 +138,9 @@ class NotificationComment implements TrackCreationInterface, TrackUpdateInterfac $this->recentlyPersisted = true; } - public function setContent(string $content): self + public function setContent(?string $content): self { - $this->content = $content; + $this->content = (string) $content; return $this; } diff --git a/src/Bundle/ChillMainBundle/Resources/views/Notification/_item_comments.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Notification/_item_comments.html.twig index b741abf4a..121111b03 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Notification/_item_comments.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Notification/_item_comments.html.twig @@ -15,11 +15,11 @@
{{ 'notification.comments_list'|trans }}
- + {% if notification.comments|length > 0 %}{{ 'Write a new comment'|trans }}
- + {{ form_start(appendCommentForm) }} {{ form_errors(appendCommentForm) }} {{ form_widget(appendCommentForm.content) }} + {{ form_errors(appendCommentForm.content) }}