diff --git a/src/Entity/Parts/PartTraits/BasicPropertyTrait.php b/src/Entity/Parts/PartTraits/BasicPropertyTrait.php index 57941140..200c1559 100644 --- a/src/Entity/Parts/PartTraits/BasicPropertyTrait.php +++ b/src/Entity/Parts/PartTraits/BasicPropertyTrait.php @@ -46,6 +46,7 @@ use App\Entity\Parts\Category; use App\Entity\Parts\Footprint; use App\Security\Annotations\ColumnSecurity; use App\Validator\Constraints\Selectable; +use Symfony\Component\Validator\Constraints as Assert; trait BasicPropertyTrait { @@ -83,6 +84,7 @@ trait BasicPropertyTrait * @ORM\JoinColumn(name="id_category", referencedColumnName="id", nullable=false) * @ColumnSecurity(prefix="category", type="App\Entity\Parts\Category") * @Selectable() + * @Assert\NotNull(message="validator.select_valid_category") */ protected $category; @@ -196,7 +198,7 @@ trait BasicPropertyTrait * * @return $this */ - public function setCategory(Category $category): self + public function setCategory(?Category $category): self { $this->category = $category; diff --git a/src/Form/Part/PartBaseType.php b/src/Form/Part/PartBaseType.php index bb7d4471..6be12032 100644 --- a/src/Form/Part/PartBaseType.php +++ b/src/Form/Part/PartBaseType.php @@ -131,6 +131,9 @@ class PartBaseType extends AbstractType 'label' => 'part.edit.category', 'disable_not_selectable' => true, 'disabled' => ! $this->security->isGranted('category.edit', $part), + 'constraints' => [ + + ] ]) ->add('footprint', StructuralEntityType::class, [ 'class' => Footprint::class, diff --git a/translations/validators.de.xlf b/translations/validators.de.xlf index fdf7caf3..4fbfc2ab 100644 --- a/translations/validators.de.xlf +++ b/translations/validators.de.xlf @@ -167,5 +167,11 @@ Der Benutzername darf nur Buchstaben, Zahlen, Unterstriche, Punkte, Plus- oder Minuszeichen enthalten. + + + validator.select_valid_category + Bitte wählen Sie eine gültige Kategorie. + + diff --git a/translations/validators.en.xlf b/translations/validators.en.xlf index b408eaaa..2408970a 100644 --- a/translations/validators.en.xlf +++ b/translations/validators.en.xlf @@ -185,5 +185,11 @@ You can not assign children element as parent (This would cause loops). + + + validator.select_valid_category + Please select a valid category! + +