You are here

public function CropTypeMachineNameValidationConstraintValidator::validate in Crop API 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/Validation/Constraint/CropTypeMachineNameValidationConstraintValidator.php \Drupal\crop\Plugin\Validation\Constraint\CropTypeMachineNameValidationConstraintValidator::validate()

File

src/Plugin/Validation/Constraint/CropTypeMachineNameValidationConstraintValidator.php, line 23

Class

CropTypeMachineNameValidationConstraintValidator
Checks if the crop type is valid.

Namespace

Drupal\crop\Plugin\Validation\Constraint

Code

public function validate($value, Constraint $constraint) {

  // '0' is invalid, since elsewhere we check it using empty().

  /** @var \Drupal\crop\Entity\CropType $value */
  if (trim($value
    ->id()) == '0') {
    $this->context
      ->buildViolation($constraint->message)
      ->atPath('id')
      ->addViolation();
  }
}