class CropTypeAspectRatioValidationConstraintValidator in Crop API 8.2
Same name and namespace in other branches
- 8 src/Plugin/Validation/Constraint/CropTypeAspectRatioValidationConstraintValidator.php \Drupal\crop\Plugin\Validation\Constraint\CropTypeAspectRatioValidationConstraintValidator
Checks if the crop type is valid.
Hierarchy
- class \Drupal\crop\Plugin\Validation\Constraint\CropTypeAspectRatioValidationConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator
Expanded class hierarchy of CropTypeAspectRatioValidationConstraintValidator
File
- src/
Plugin/ Validation/ Constraint/ CropTypeAspectRatioValidationConstraintValidator.php, line 11
Namespace
Drupal\crop\Plugin\Validation\ConstraintView source
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();
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CropTypeAspectRatioValidationConstraintValidator:: |
protected | property | Validator 2.5 and upwards compatible execution context. | |
CropTypeAspectRatioValidationConstraintValidator:: |
public | function | Checks if the passed value is valid. |