You are here

public function GeoConstraintValidator::validate in Geofield 8

File

src/Plugin/Validation/Constraint/GeoConstraintValidator.php, line 45

Class

GeoConstraintValidator
Validates the GeoType constraint.

Namespace

Drupal\geofield\Plugin\Validation\Constraint

Code

public function validate($value, Constraint $constraint) {
  if (isset($value)) {
    $valid_geometry = TRUE;
    try {
      if (!$this->geoPhpWrapper
        ->load($value)) {
        $valid_geometry = FALSE;
      }
    } catch (\Exception $e) {
      $valid_geometry = FALSE;
    }
    if (!$valid_geometry) {
      $this->context
        ->addViolation($constraint->message, [
        '@value' => $value,
      ]);
    }
  }
}