From 082cd1648662b422df0c5c5a7c36cb52cce697ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Fri, 22 Jul 2022 00:48:51 +0200 Subject: [PATCH] Disallow attachments without attachment types. This should partly fixes issue #131. TODO: Change database structure so attachment_type is not nullable. --- src/Entity/Attachments/Attachment.php | 2 ++ translations/validators.en.xlf | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/src/Entity/Attachments/Attachment.php b/src/Entity/Attachments/Attachment.php index 5da7e227..9f9b54b8 100644 --- a/src/Entity/Attachments/Attachment.php +++ b/src/Entity/Attachments/Attachment.php @@ -25,6 +25,7 @@ namespace App\Entity\Attachments; use App\Entity\Base\AbstractNamedDBElement; use App\Validator\Constraints\Selectable; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Validator\Constraints as Assert; use function in_array; use InvalidArgumentException; use LogicException; @@ -105,6 +106,7 @@ abstract class Attachment extends AbstractNamedDBElement * @ORM\ManyToOne(targetEntity="AttachmentType", inversedBy="attachments_with_type") * @ORM\JoinColumn(name="type_id", referencedColumnName="id") * @Selectable() + * @Assert\NotNull(message="validator.attachment.must_not_be_null") */ protected $attachment_type; diff --git a/translations/validators.en.xlf b/translations/validators.en.xlf index bbcbee74..8ecde9ad 100644 --- a/translations/validators.en.xlf +++ b/translations/validators.en.xlf @@ -215,5 +215,11 @@ This location can only contain a single part and it is already full! + + + validator.attachment.must_not_be_null + You must select an attachment type! + +