977155d61bc30fb7476189249dc84345c54ef69b
[yaffs-website] / web / modules / contrib / crop / src / Plugin / Validation / Constraint / CropTypeMachineNameValidationConstraintValidator.php
1 <?php
2
3 namespace Drupal\crop\Plugin\Validation\Constraint;
4
5 use Symfony\Component\Validator\Constraint;
6 use Symfony\Component\Validator\ConstraintValidator;
7
8 /**
9  * Checks if the crop type is valid.
10  */
11 class CropTypeMachineNameValidationConstraintValidator extends ConstraintValidator {
12
13   /**
14    * Validator 2.5 and upwards compatible execution context.
15    *
16    * @var \Symfony\Component\Validator\Context\ExecutionContextInterface
17    */
18   protected $context;
19
20   /**
21    * {@inheritdoc}
22    */
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)
28         ->atPath('id')
29         ->addViolation();
30     }
31   }
32
33 }