diff --git a/src/Plugin/Validation/Constraint/ChoiceConstraint.php b/src/Plugin/Validation/Constraint/ChoiceConstraint.php new file mode 100644 index 0000000000000000000000000000000000000000..3c436ade12a10f62d2241aa78622e4c4b3b8b0cb --- /dev/null +++ b/src/Plugin/Validation/Constraint/ChoiceConstraint.php @@ -0,0 +1,28 @@ +<?php + +namespace Drupal\field_validation\Plugin\Validation\Constraint; + +use Symfony\Component\Validator\Constraints\Choice; +use Symfony\Component\Validator\Constraints\ChoiceValidator; + +/** + * Choice constraint. + * + * @Constraint( + * id = "Choice", + * label = @Translation("Choice", context = "Validation"), + * ) + */ +class ChoiceConstraint extends Choice { + + public $minMessage = 'You must select at least %limit choice.|You must select at least %limit choices.'; + public $maxMessage = 'You must select at most %limit choice.|You must select at most %limit choices.'; + + /** + * {@inheritdoc} + */ + public function validatedBy(): string { + return ChoiceValidator::class; + } + +}