From b58c79500b94d9bfec55db30131cfeee5e341b56 Mon Sep 17 00:00:00 2001 From: howard ge <14788-g089h515r806@users.noreply.drupalcode.org> Date: Sun, 20 Aug 2023 18:24:04 +0800 Subject: [PATCH] Issue #3382098 by g089h515r806: Add support for Symfony Choice Constraint --- .../Constraint/ChoiceConstraint.php | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/Plugin/Validation/Constraint/ChoiceConstraint.php diff --git a/src/Plugin/Validation/Constraint/ChoiceConstraint.php b/src/Plugin/Validation/Constraint/ChoiceConstraint.php new file mode 100644 index 0000000..3c436ad --- /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; + } + +} -- GitLab