You are here

public function CropTypeAspectRatioValidationConstraintValidator::validate in Crop API 8.2

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

File

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

Class

CropTypeAspectRatioValidationConstraintValidator
Checks if the crop type is valid.

Namespace

Drupal\crop\Plugin\Validation\Constraint

Code

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

  /** @var \Drupal\crop\Entity\CropType $value */
  $aspect_ratio = $value
    ->getAspectRatio();
  if (!empty($aspect_ratio) && !preg_match($value::VALIDATION_REGEXP, $aspect_ratio)) {
    $this->context
      ->buildViolation($constraint->message)
      ->atPath('aspect_ratio')
      ->addViolation();
  }
}