CropTypeAspectRatioValidationConstraintValidator.php in Crop API 8
Same filename and directory in other branches
Namespace
Drupal\crop\Plugin\Validation\ConstraintFile
src/Plugin/Validation/Constraint/CropTypeAspectRatioValidationConstraintValidator.phpView source
<?php
namespace Drupal\crop\Plugin\Validation\Constraint;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
/**
* Checks if the crop type is valid.
*/
class CropTypeAspectRatioValidationConstraintValidator extends ConstraintValidator {
/**
* Validator 2.5 and upwards compatible execution context.
*
* @var \Symfony\Component\Validator\Context\ExecutionContextInterface
*/
protected $context;
/**
* {@inheritdoc}
*/
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();
}
}
}
Classes
Name | Description |
---|---|
CropTypeAspectRatioValidationConstraintValidator | Checks if the crop type is valid. |