3 namespace Drupal\crop\Plugin\Validation\Constraint;
5 use Symfony\Component\Validator\Constraint;
6 use Symfony\Component\Validator\ConstraintValidator;
9 * Checks if the crop type is valid.
11 class CropTypeMachineNameValidationConstraintValidator extends ConstraintValidator {
14 * Validator 2.5 and upwards compatible execution context.
16 * @var \Symfony\Component\Validator\Context\ExecutionContextInterface
23 public function validate($value, Constraint $constraint) {
24 // '0' is invalid, since elsewhere we check it using empty().
25 /** @var \Drupal\crop\Entity\CropType $value */
26 if (trim($value->id()) == '0') {
27 $this->context->buildViolation($constraint->message)