class GeoConstraintValidator in Geofield 8
Validates the GeoType constraint.
Hierarchy
- class \Drupal\geofield\Plugin\Validation\Constraint\GeoConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator implements ContainerInjectionInterface
Expanded class hierarchy of GeoConstraintValidator
1 file declares its use of GeoConstraintValidator
- ConstraintsTest.php in tests/src/ Kernel/ ConstraintsTest.php 
File
- src/Plugin/ Validation/ Constraint/ GeoConstraintValidator.php, line 14 
Namespace
Drupal\geofield\Plugin\Validation\ConstraintView source
class GeoConstraintValidator extends ConstraintValidator implements ContainerInjectionInterface {
  /**
   * The geoPhpWrapper service.
   *
   * @var \Drupal\geofield\GeoPHP\GeoPHPInterface
   */
  protected $geoPhpWrapper;
  /**
   * Constructs a new GeoConstraintValidator object.
   *
   * @param \Drupal\geofield\GeoPHP\GeoPHPInterface $geophp_wrapper
   *   The geoPhpWrapper.
   */
  public function __construct(GeoPHPInterface $geophp_wrapper) {
    $this->geoPhpWrapper = $geophp_wrapper;
  }
  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('geofield.geophp'));
  }
  /**
   * {@inheritdoc}
   */
  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,
        ]);
      }
    }
  }
}Members
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| GeoConstraintValidator:: | protected | property | The geoPhpWrapper service. | |
| GeoConstraintValidator:: | public static | function | Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: | |
| GeoConstraintValidator:: | public | function | Checks if the passed value is valid. | |
| GeoConstraintValidator:: | public | function | Constructs a new GeoConstraintValidator object. | 
