From 2ff34688bbc2c8244e63d4fbe5aac82c47aeb34b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 19 Jan 2022 13:57:21 +0100 Subject: [PATCH] fix validation for notification --- src/Bundle/ChillMainBundle/Entity/Notification.php | 11 +++++++---- .../Resources/views/Notification/show.html.twig | 2 ++ .../ChillMainBundle/translations/validators.fr.yml | 5 +++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Entity/Notification.php b/src/Bundle/ChillMainBundle/Entity/Notification.php index e566a8d78..0624fff39 100644 --- a/src/Bundle/ChillMainBundle/Entity/Notification.php +++ b/src/Bundle/ChillMainBundle/Entity/Notification.php @@ -17,6 +17,7 @@ use DateTimeInterface; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Validator\Constraints as Assert; /** * @ORM\Entity @@ -32,6 +33,7 @@ class Notification implements TrackUpdateInterface /** * @ORM\ManyToMany(targetEntity=User::class) * @ORM\JoinTable(name="chill_main_notification_addresses_user") + * @Assert\Count(min="1", minMessage="notification.At least one addressee") */ private Collection $addressees; @@ -80,6 +82,7 @@ class Notification implements TrackUpdateInterface /** * @ORM\Column(type="text", options={"default": ""}) + * @Assert\NotBlank(message="notification.Title must be defined") */ private string $title = ''; @@ -286,9 +289,9 @@ class Notification implements TrackUpdateInterface return $this; } - public function setMessage(string $message): self + public function setMessage(?string $message): self { - $this->message = $message; + $this->message = (string) $message; return $this; } @@ -314,9 +317,9 @@ class Notification implements TrackUpdateInterface return $this; } - public function setTitle(string $title): Notification + public function setTitle(?string $title): Notification { - $this->title = $title; + $this->title = (string) $title; return $this; } diff --git a/src/Bundle/ChillMainBundle/Resources/views/Notification/show.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Notification/show.html.twig index d556da65f..690f2187d 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Notification/show.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Notification/show.html.twig @@ -87,6 +87,7 @@ {% endif %} + {% if appendCommentForm is not null %}

{{ 'Write a new comment'|trans }}

@@ -102,6 +103,7 @@ {{ form_end(appendCommentForm) }}
+ {% endif %}