You are here

class CropTypeAspectRatioValidationConstraintValidator in Crop API 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Validation/Constraint/CropTypeAspectRatioValidationConstraintValidator.php \Drupal\crop\Plugin\Validation\Constraint\CropTypeAspectRatioValidationConstraintValidator

Checks if the crop type is valid.

Hierarchy

Expanded class hierarchy of CropTypeAspectRatioValidationConstraintValidator

File

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

Namespace

Drupal\crop\Plugin\Validation\Constraint
View 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

Namesort descending Modifiers Type Description Overrides
CropTypeAspectRatioValidationConstraintValidator::$context protected property Validator 2.5 and upwards compatible execution context.
CropTypeAspectRatioValidationConstraintValidator::validate public function Checks if the passed value is valid.