You are here

class AddressFormatConstraintValidator in Address 8

Validates the address format constraint.

Hierarchy

Expanded class hierarchy of AddressFormatConstraintValidator

File

src/Plugin/Validation/Constraint/AddressFormatConstraintValidator.php, line 15

Namespace

Drupal\address\Plugin\Validation\Constraint
View source
class AddressFormatConstraintValidator extends ExternalValidator implements ContainerInjectionInterface {

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('address.address_format_repository'), $container
      ->get('address.subdivision_repository'));
  }

  /**
   * {@inheritdoc}
   */
  protected function addViolation($field, $message, $invalid_value, AddressFormat $address_format) {
    $labels = LabelHelper::getFieldLabels($address_format);
    $label = $labels[$field];
    $this->context
      ->buildViolation($message, [
      '@name' => $label,
    ])
      ->atPath(FieldHelper::getPropertyName($field))
      ->setInvalidValue($invalid_value)
      ->addViolation();
  }

}

Members